///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Z88DK INTRINSICS
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

replace restart {
	call	_SECTION_SIZE_CODE
} by {
	nop	; EXTERN __CODE_END_tail
	nop	; EXTERN __CODE_head
	ld	hl,#(__CODE_END_tail - __CODE_head)
	; peephole z88dk-intrinsic-section-size
}

replace restart {
	call	_SECTION_SIZE_DATA
} by {
	nop	; EXTERN __DATA_END_tail
	nop	; EXTERN __DATA_head
	ld	hl,#(__DATA_END_tail - __DATA_head)
	; peephole z88dk-intrinsic-section-size
}

replace restart {
	call	_SECTION_SIZE_BSS
} by {
	nop	; EXTERN __BSS_UNINITIALIZED_head
	nop	; EXTERN __BSS_head
	ld	hl,#(__BSS_UNINITIALIZED_head - __BSS_head)
	; peephole z88dk-intrinsic-section-size
}

replace restart {
	call	_SECTION_ORG_%1
} by {
	nop	; EXTERN __%1_head
	ld	hl,#__%1_head
	; peephole z88dk-intrinsic-section-org
}

replace restart {
	call	_SECTION_END_%1
} by {
	nop	; EXTERN __%1_tail
	ld	hl,#__%1_tail
	; peephole z88dk-intrinsic-section-end
}

replace restart {
	call	_SECTION_SIZE_%1
} by {
	nop	; EXTERN __%1_size
	ld	hl,#__%1_size
	; peephole z88dk-intrinsic-section-size
}

replace restart {
	call	_intrinsic_outi_num_256
} by {
	call	____sdcc_outi_256
	; peephole z88dk-intrinsic-outi-num-256
}

replace restart {
	jp	_intrinsic_outi_num_256
} by {
	jp	____sdcc_outi_256
	; peephole z88dk-intrinsic-outi-num-256
}

replace restart {
	call	_intrinsic_outi_num_128
} by {
	call	____sdcc_outi_128
	; peephole z88dk-intrinsic-outi-num-128
}

replace restart {
	jp	_intrinsic_outi_num_128
} by {
	jp	____sdcc_outi_128
	; peephole z88dk-intrinsic-outi-num-128
}

barrier

replace restart {
	call	_intrinsic_outi_num_%1
} by {
	call	____sdcc_outi-(%1*2)
	; peephole z88dk-intrinsic-outi-num-%1
}

replace restart {
	jp	_intrinsic_outi_num_%1
} by {
	jp	____sdcc_outi-(%1*2)
	; peephole z88dk-intrinsic-outi-num-%1
}

replace restart {
	call	_intrinsic_outi_port_%1
} by {
	ld	c,#%1
	; peephole z88dk-intrinsic-outi-port-%1
}

replace restart {
	call	_intrinsic_outi
} by {
	; peephole z88dk-intrinsic-outi
}

barrier

replace restart {
	call	_intrinsic_ini_num_512
} by {
	call	____sdcc_ini_512
	; peephole z88dk-intrinsic-ini-num-512
}

replace restart {
	jp	_intrinsic_ini_num_512
} by {
	jp	____sdcc_ini_512
	; peephole z88dk-intrinsic-ini-num-512
}

replace restart {
	call	_intrinsic_ini_num_256
} by {
	call	____sdcc_ini_256
	; peephole z88dk-intrinsic-ini-num-256
}

replace restart {
	jp	_intrinsic_ini_num_256
} by {
	jp	____sdcc_ini_256
	; peephole z88dk-intrinsic-ini-num-256
}

replace restart {
	call	_intrinsic_ini_num_128
} by {
	call	____sdcc_ini_128
	; peephole z88dk-intrinsic-ini-num-128
}

replace restart {
	jp	_intrinsic_ini_num_128
} by {
	jp	____sdcc_ini_128
	; peephole z88dk-intrinsic-ini-num-128
}

barrier

replace restart {
	call	_intrinsic_ini_num_%1
} by {
	call	____sdcc_ini-(%1*2)
	; peephole z88dk-intrinsic-ini-num-%1
}

replace restart {
	jp	_intrinsic_ini_num_%1
} by {
	jp	____sdcc_ini-(%1*2)
	; peephole z88dk-intrinsic-ini-num-%1
}

replace restart {
	call	_intrinsic_ini_port_%1
} by {
	ld	c,#%1
	; peephole z88dk-intrinsic-ini-port-%1
}

replace restart {
	call	_intrinsic_ini
} by {
	; peephole z88dk-intrinsic-ini
}

barrier

replace restart {
	call	_intrinsic_ldi_num_256
} by {
	call	____sdcc_ldi_256
	; peephole z88dk-intrinsic-ldi-num-256
}

replace restart {
	jp	_intrinsic_ldi_num_256
} by {
	jp	____sdcc_ldi_256
	; peephole z88dk-intrinsic-ldi-num-256
}

replace restart {
	call	_intrinsic_ldi_num_128
} by {
	call	____sdcc_ldi_128
	; peephole z88dk-intrinsic-ldi-num-128
}

replace restart {
	jp	_intrinsic_ldi_num_128
} by {
	jp	____sdcc_ldi_128
	; peephole z88dk-intrinsic-ldi-num-128
}

barrier

replace restart {
	call	_intrinsic_ldi_num_%1
} by {
	call	____sdcc_ldi-(%1*2)
	; peephole z88dk-intrinsic-ldi-num-%1
}

replace restart {
	jp	_intrinsic_ldi_num_%1
} by {
	jp	____sdcc_ldi-(%1*2)
	; peephole z88dk-intrinsic-ldi-num-%1
}

replace restart {
	call	_intrinsic_ldi
} by {
	pop	de
	pop	hl
	; peephole z88dk-intrinsic-ldi
}

replace restart {
	call	____sdcc_ldi%1
	ret
} by {
	jp	____sdcc_ldi%1
	; peephole z88dk-intrinsic-ldi-tailcall
}

barrier

replace restart {
	call	_intrinsic_slp
} by {
	slp
	; peephole z88dk-intrinsic-slp
}

replace restart {
	jp	_intrinsic_slp
} by {
	slp
	ret
	; peephole z88dk-intrinsic-slp
}

replace restart {
	call	_intrinsic_stub
} by {
	; peephole z88dk-intrinsic-stub
}

replace restart {
	jp	_intrinsic_stub
} by {
	ret
	; peephole z88dk-intrinsic-stub
}

replace restart {
	call	_intrinsic_di
} by {
	di
	; peephole z88dk-intrinsic-di
}

replace restart {
	jp	_intrinsic_di
} by {
	di
	ret
	; peephole z88dk-intrinsic-di
}

replace restart {
	call	_intrinsic_ei
} by {
	ei
	; peephole z88dk-intrinsic-ei
}

replace restart {
	jp	_intrinsic_ei
} by {
	ei
	ret
	; peephole z88dk-intrinsic-ei
}

replace restart {
	call	_intrinsic_halt
} by {
	halt
	; peephole z88dk-intrinsic-halt
}

replace restart {
	jp	_intrinsic_halt
} by {
	halt
	ret
	; peephole z88dk-intrinsic-halt
}

replace restart {
	call	_intrinsic_label_%1
} by {
%1::
	; peephole z88dk-intrinsic-label %1
}

replace restart {
	jp	_intrinsic_label_%1
} by {
%1::
	ret
	; peephole z88dk-intrinsic-label %1
}

replace restart {
	call	_intrinsic_load16_%1
} by {
	ld	hl,(#%1)
	; peephole z88dk-intrinsic-load (%1)
}

replace restart {
	jp	_intrinsic_load16_%1
} by {
	ld	hl,(#%1)
	ret
	; peephole z88dk-intrinsic-load (%1)
}

replace restart {
	call	_intrinsic_store16_address_%1
	call	_intrinsic_store16_value_%2
} by {
	ld	hl,#%2
	ld	(#%1),hl
	; peephole z88dk-intrinsic-store (%1),%2
} 

replace restart {
	call	_intrinsic_reti
} by {
	reti
	; peephole z88dk-intrinsic-reti
}

replace restart {
	jp	_intrinsic_reti
} by {
	reti
	; peephole z88dk-intrinsic-reti
}

replace restart {
	call	_intrinsic_retn
} by {
	retn
	; peephole z88dk-intrinsic-retn
}

replace restart {
	jp	_intrinsic_retn
} by {
	retn
	; peephole z88dk-intrinsic-retn
}

replace restart {
	call	_intrinsic_im_0
} by {
	im	0
	; peephole z88dk-intrinsic-im-0
}

replace restart {
	jp	_intrinsic_im_0
} by {
	im	0
	ret
	; peephole z88dk-intrinsic-im-0
}

replace restart {
	call	_intrinsic_im_1
} by {
	im	1
	; peephole z88dk-intrinsic-im-1
}

replace restart {
	jp	_intrinsic_im_1
} by {
	im	1
	ret
	; peephole z88dk-intrinsic-im-1
}

replace restart {
	call	_intrinsic_im_2
} by {
	im	2
	; peephole z88dk-intrinsic-im-2
}

replace restart {
	jp	_intrinsic_im_2
} by {
	im	2
	ret
	; peephole z88dk-intrinsic-im-2
}

replace restart {
	call	_intrinsic_nop
} by {
	nop
	; peephole z88dk-intrinsic-nop
}

replace restart {
	jp	_intrinsic_nop
} by {
	nop
	ret
	; peephole z88dk-intrinsic-nop
}

replace restart {
	call	_intrinsic_exx
} by {
	exx
	; peephole z88dk-intrinsic-exx
}

replace restart {
	jp	_intrinsic_exx
} by {
	exx
	ret
	; peephole z88dk-intrinsic-exx
}

replace restart {
	call	_intrinsic_ex_de_hl
} by {
	ex	de,hl
	; peephole z88dk-intrinsic-ex-de-hl
}

replace restart {
	jp	_intrinsic_ex_de_hl
} by {
	ex	de,hl
	ret
	; peephole z88dk-intrinsic-ex-de-hl
}

replace restart {
	call	_intrinsic_return_bc
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-intrinsic-return-bc
}

replace restart {
	jp	_intrinsic_return_bc
} by {
	ld	l,c
	ld	h,b
	ret
	; peephole z88dk-intrinsic-return-bc
}

replace restart {
	call	_intrinsic_return_de
} by {
	ld	l,e
	ld	h,d
	; peephole z88dk-intrinsic-return-de
}

replace restart {
	jp	_intrinsic_return_de
} by {
	ld	l,e
	ld	h,d
	ret
	; peephole z88dk-intrinsic-return-de
}

replace restart {
	call	_intrinsic_swap_endian_16_fastcall
} by {
	ld	a,l
	ld	l,h
	ld	h,a
	; peephole z88dk-intrinsic-swap-endian-16
}

replace restart {
	jp	_intrinsic_swap_endian_16_fastcall
} by {
	ld	a,l
	ld	l,h
	ld	h,a
	ret
	; peephole z88dk-intrinsic-swap-endian-16
}

replace restart {
	call	_intrinsic_swap_endian_32_fastcall
} by {
	ld	a,d
	ld	d,l
	ld	l,a
	ld	a,e
	ld	e,h
	ld	h,a
	; peephole z88dk-intrinsic-swap-endian-32
}

replace restart {
	jp	_intrinsic_swap_endian_32_fastcall
} by {
	ld	a,d
	ld	d,l
	ld	l,a
	ld	a,e
	ld	e,h
	ld	h,a
	ret
	; peephole z88dk-intrinsic-swap-endian-32
}

replace restart {
	call	_intrinsic_swap_word_32_fastcall
} by {
	ex	de,hl
	; peephole z88dk-intrinsic-swap-word-32
}

replace restart {
	jp	_intrinsic_swap_word_32_fastcall
} by {
	ex	de,hl
	ret
	; peephole z88dk-intrinsic-swap-word-32
}

replace restart {
	ret
	ret
} by {
	ret
	; peephole z88dk-intrinsic-retret
}


barrier


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Z88DK BUGFIXES APPLIED TO SDCC FOR #9570
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

replace restart {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ld	hl,#%1
	ld	l,(hl)
	ld	hl,#%1 + 1
	ld	h,(hl)
	ld	hl,#%1 + 2
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	; peephole z88dk-bugfix-1
}
// if notVolatile

replace restart {
	ld	hl,#%1
	ld	l,(hl)
	ld	hl,#%1 + 1
	ld	h,(hl)
	ld	hl,#%1 + 2
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	hl,(#%1)
	ld	de,(#%1 + 2)
	; peephole z88dk-bugfix-2
}

replace restart {
	ld	hl,#%1
	ld	hl,#%2
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
} by {
	ld	hl,#%1
	ld	a,(#%2)
	ld	(hl),a
	inc	hl
	ld	a,(#%2 + 1)
	ld	(hl),a
	ld	hl,#%2 + 1
	; peephole z88dk-bugfix-3a
}

replace restart {
	ld	hl,#%1
	ld	hl,#%2
	ld	a,(hl)
	ld	(hl),a
} by {
	ld	a,(#%2)
	ld	(#%1),a
	; peephole z88dk-bugfix-3b
}

replace restart {
	ld	a,i
	di
	push	af
} by {
	call	____sdcc_cpu_push_di
	; peephole z88dk-bugfix-4a-critical-open-1
}

replace restart {
	pop	af
	jp	PO,%1
	ei
%1:
} by {
	call	____sdcc_cpu_pop_ei
%1:
	; peephole z88dk-bugfix-4c-critical-close-1
}

replace restart {
	in	a,(%1)
	in	a,(%1)
	ld	l,a
	in	a,(%1)
	ld	h,a
} by {
	ld	hl,(%1)
	; peephole z88dk-bugfix-5a-sdcc-2523
}

replace restart {
	in	a,(%1)
	in	a,(%1)
	ld	e,a
	in	a,(%1)
	ld	d,a
} by {
	ld	de,(%1)
	; peephole z88dk-bugfix-5b-sdcc-2523
}

replace restart {
	in	a,(%1)
	in	a,(%1)
	ld	c,a
	in	a,(%1)
	ld	b,a
} by {
	ld	bc,(%1)
	; peephole z88dk-bugfix-5c-sdcc-2523
}

replace restart {
	ld	a,(hl)
	and	a,#%5
	jp	NZ,%1
	jp	%2
%1:
	jp	%3
%2:
	or	a, a
	jp	NZ,%3
} by {
	ld	a,(hl)
	and	a,#%5
	jp	NZ,%1
	jp	%2
%1:
	jp	%3
%2:
	ld	a,(hl)
	and	a,#0x01
	jp	NZ,%3
	; peephole z88dk-bugfix-6a
}

replace restart {
	ld	a,(hl)
	and	a,#%5
	jp	NZ,%1
	jp	%2
%1:
	or	a, a
	jp	NZ,%2
} by {
	ld	a,(hl)
	and	a,#%5
	jp	NZ,%1
	jp	%2
%1:
	ld	a,(hl)
	and	a,#0x01
	jp	NZ,%2
	; peephole z88dk-bugfix-6b
}

replace restart {
	ld	hl,#%1
	ld	(hl),l
	inc	hl
	ld	(hl),h
} by {
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-bugfix-7a
}

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),l
	inc	hl
	ld	(hl),h
} by {
	ld	(#%1+%2),hl
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-bugfix-7b
}

replace restart {
	ld	hl,#%1
	ld (hl),l
} by {
	ld	a,l
	ld	(#%1),a
	; peephole z88dk-bugfix-8a1
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld (hl),l
} by {
	ld	a,l
	ld	hl,#%1
	ld	(hl),a
	; peephole z88dk-bugfix-8a2
} if notUsed('a')

replace restart {
	ld	hl,#%1
	ld	(hl),l
} by {
	ld	e,l
	ld	hl,#%1
	ld	(hl),e
	; peephole z88dk-bugfix-8a3
} if notUsed('e')

replace restart {
	ld	hl,#%1
	ld	(hl),l
} by {
	ld	c,l
	ld	hl,#%1
	ld	(hl),c
	; peephole z88dk-bugfix-8a4
} if notUsed('c')

replace restart {
	ld	hl,#%1 + %2
	ld (hl),l
} by {
	ld	a,l
	ld	(#%1 + %2),a
	; peephole z88dk-bugfix-8b1
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	ld (hl),l
} by {
	ld	a,l
	ld	hl,#%1 + %2
	ld	(hl),a
	; peephole z88dk-bugfix-8b2
} if notUsed('a')

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),l
} by {
	ld	e,l
	ld	hl,#%1 + %2
	ld	(hl),e
	; peephole z88dk-bugfix-8b3
} if notUsed('e')

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),l
} by {
	ld	c,l
	ld	hl,#%1 + %2
	ld	(hl),c
	; peephole z88dk-bugfix-8b4
} if notUsed('c')

replace restart {
	ld	hl,#%1
	ld	(hl),h
	inc	hl
	ld	(hl),l
} by {
	ld	a,l
	ld	l,h
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-bugfix-9a
} if notUsed('a')

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),h
	inc	hl
	ld	(hl),l
} by {
	ld	a,l
	ld	l,h
	ld	h,a
	ld	(#%1+%2),hl
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-bugfix-9b
} if notUsed('a')

replace restart {
	ld	hl,#%1
	ld	(hl),%2
	inc	hl
	ld	(hl),l
} by {
	ld	h,l
	ld	l,%2
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-bugfix-10a
} if same(%2 'a' 'b' 'c' 'd' 'e')

replace restart {
	ld	hl,#%1 + %3
	ld	(hl),%2
	inc	hl
	ld	(hl),l
} by {
	ld	h,l
	ld	l,%2
	ld	(#%1+%3),hl
	ld	hl,#%1 + %3 + 1
	; peephole z88dk-bugfix-10b
} if same(%2 'a' 'b' 'c' 'd' 'e')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	ldi
	ldi
	ldi
	ld	a,(hl)
	ld	(de),a
	inc	bc
	inc	bc
	inc	bc
	; peephole z88dk-bugfix-11a
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	(hl),a
} by {
	push	de
	ld	e,l
	ld	d,h
	ld	hl,#%1
	ldi
	ldi
	ldi
	ld	a,(hl)
	ld	(de),a
	inc	bc
	inc	bc
	inc	bc
	pop	de
	; peephole z88dk-bugfix-11b
}

// z88dk-bugfix-12a and z88dk-bugfix-12b removed in #1811

replace restart
{
	push	hl
	pop	iy
	push	hl
	push	bc
	push	de
	push	iy
	pop	de
	pop	hl
	pop	bc
	pop	hl
	push	hl
} by {
	push	hl
	push	hl
	pop	iy
	ex	de,hl
	; peephole z88dk-bugfix-13
}

replace restart {
	ld	a,l
	ld	d,h
	ld	d,a
	ld	h,d
} by {
	ld	a,l
	ld	d,l
	; peephole z88dk-bugfix-14
}

barrier


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// SDCC PEEPHOLE RULES EXCEPT JP->JR FROM #9570
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

// peeph-z80.def - Z80 peephole rules
//
// Some of these peepholes could be potentially moved to peeph.def, but a
// GBZ80 expert should have a look at them before.
//
// (c) Philipp Klaus Krause (pkk@spth.de, philipp@colecovision.eu) 2006 - 2012
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

replace restart {
	ld	%1, %1
} by {
	; peephole 0 removed redundant load from %1 into %1.
} if notVolatile(%1)

replace restart {
	ld	%1, %2
} by {
	; peephole 1 removed dead load from %2 into %1.
} if notVolatile(%1), notUsed(%1), notVolatile(%2)

replace restart {
	add	ix,sp
} by {
	; peephole 1a removed dead frame pointer setup.
} if notUsed('ix')

replace restart {
	ld	%1, %2 + %3
} by {
	; peephole 2 removed dead load from %2 + %3 into %1.
} if notVolatile(%1), notUsed(%1)
// Should probably check for notVolatile(%2), too, but gives many false positives and no regression tests fail.

replace restart {
	ld	%1, (iy)
} by {
	ld	%1, 0 (iy)
	; peephole 3 made 0 offset explicit.
}

replace restart {
	ld	(iy), %1
} by {
	ld	0 (iy), %1
	; peephole 4 made 0 offset explicit.
}

replace restart {
	inc	hl
} by {
	; peephole 5 removed dead increment of hl.
} if notUsed('hl')

replace restart {
	dec	hl
} by {
	; peephole 6 removed dead decrement of hl.
} if notUsed('hl')

replace restart {
	ld	%1, %2 (iy)
} by {
	; peephole 7 removed dead load from %2 (iy) into %1.
} if notUsed(%1)
// Should probably check for notVolatile(), but gives many false positives and no regression tests fail.

replace restart {
	ld	%1, %2 (ix)
} by {
	; peephole 8 removed dead load from %2 (ix) into %1.
} if notUsed(%1)

replace restart {
	ld	%1, %2
	ld	%3, %1
} by {
	; peephole 9 loaded %3 from %2 directly instead of going through %1.
	ld	%3, %2
} if canAssign(%3 %2), notVolatile(%1), notUsed(%1)

replace restart {
	ld	%1, %2
	ld	%3, %4
	ld	%5, %1
} by {
	ld	%5, %2
	; peephole 10 loaded %5 from %2 directly instead of going through %1.
	ld	%3, %4
} if notUsed(%1), canAssign(%5 %2), notVolatile(%1), notVolatile(%5), operandsNotRelated(%1 %3), operandsNotRelated(%1 %4), operandsNotRelated(%2 %3), operandsNotRelated(%3 %5), operandsNotRelated(%4 %5), notSame(%3 %4 '(hl)' '(de)' '(bc)')
// Rule OK unless both %5 and %4 are volatile, but we can't express that directly.

replace restart {
	ld	%1, %2 (%3)
	ld	%4, %1
} by {
	; peephole 11 loaded %2 (%3) into %4 directly instead of going through %1.
	ld	%4, %2 (%3)
} if canAssign(%4 %2 %3), notVolatile(%1), notUsed(%1)

replace restart {
	ld	%1, %2
	ld	%3 (%4), %1
} by {
	; peephole 12 loaded %2 into %3 (%4) directly instead of going through %1.
	ld	%3 (%4), %2
} if canAssign(%3 %4 %2), notVolatile(%1), notUsed(%1)

replace restart {
	ld	%1, %2 (%3)
	ld	%4, %5 (%6)
	ld	%7, %1
} by {
	ld	%7, %2 (%3)
	; peephole 13 loaded %2 (%3) into %7 directly instead of going through %1.
	ld	%4, %5 (%6)
} if canAssign(%7 %2 %3), notVolatile(%1), notUsed(%1), notSame(%1 %4), notSame(%7 %4)

replace restart {
	ld	%1, %7
	ld	%5 (%6), %4
	ld	%2 (%3), %1
} by {
	ld	%5 (%6), %4
	; peephole 14 loaded %7 into %2 (%3) directly instead of going through %1.
	ld	%2 (%3), %7
} if canAssign(%2 %3 %7), notVolatile(%1), notUsed(%1), notSame(%1 %4)

replace restart {
	ld	%1, %2 (%3)
	ld	%4, %5
	ld	%7, %1
} by {
	ld	%7, %2 (%3)
	; peephole 15 loaded %2 (%3) into %7 directly instead of going through %1.
	ld	%4, %5
} if canAssign(%7 %2 %3), notVolatile(%1), notUsed(%1), operandsNotRelated(%1 %5), operandsNotRelated(%7 %4), operandsNotRelated(%7 %5), notSame(%4 '(hl)' '(de)' '(bc)'), notSame(%5 '(hl)' '(de)' '(bc)' '(iy)')

replace restart {
	ld	%1,#%2
	ld	a,%3 (%1)
} by {
	; peephole 16 loaded %2 into a directly instead of going through %1.
	ld	a,(#%2 + %3)
} if notUsed(%1)

replace restart {
	ld	hl,#%1
	ld	a,(hl)
} by {
	ld	a,(#%1)
	; peephole 17 loaded a from (#%1) directly instead of using hl.
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
} by {
	; peephole 18 loaded %2 into a directly instead of using hl.
	ld	a,(#%1 + %2)
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),a
} by {
	ld	(#%1),a
	; peephole 19 loaded (#%1) from a directly instead of using hl.
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),a
} by {
	ld	(#%1 + %2),a
	; peephole 20 loaded (#%1) from a directly instead of using hl.
} if notUsed('hl')

replace restart {
	srl	%1
	ld	a,%1
} by {
	ld	a,%1
	; peephole 21 shifted in a instead of %1.
	srl	a
} if notVolatile(%1), notUsed(%1)

replace restart {
	ld	e, l
	ld	d, h
	ld	a, (de)
	srl	a
	ld	(de), a
} by {
	ld	e, l
	ld	d, h
	srl	(hl)
	ld	a, (hl)
	; peephole 21a shifted in (hl) instead of a.
}

replace restart {
	ld	a, %1 (%2)
	srl	a
	ld	%1 (%2), a
} by {
	srl	%1 (%2)
	ld	a, %1 (%2)
	; peephole 21b shifted in (%2) instead of a.
}

replace restart {
	ld	iy, #%1
	ld	%2, %3 (iy)
	srl	%2
	bit %4, %3 (iy)
} by {
	ld	hl, #%1 + %3
	; peephole 21c used hl instead of iy.
	ld	%2, (hl)
	srl %2
	bit %4, (hl)
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	%1,(hl)
	ld	a,%2 (%3)
	sub	a,%1
} by {
	ld	a,%2 (%3)
	; peephole 22 used (hl) in sub directly instead of going through %1.
	sub	a,(hl)
} if notVolatile(%1), notUsed(%1)

replace restart {
	inc	bc
	ld	l,c
	ld	h,b
} by {
	ld	l,c
	ld	h,b
	; peephole 23 incremented in hl instead of bc.
	inc	hl
} if notUsed('bc')

replace restart {
	inc	de
	ld	l,e
	ld	h,d
} by {
	ld	l,e
	ld	h,d
	; peephole 24 incremented in hl instead of de.
	inc	hl
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	ld	a,#%1
} by {
	ld	a,#%1
	ld	c,l
	ld	b,h
	; peephole 25a delay copy of hl into bc
}

replace restart {
	ld	c,l
	ld	b,h
	ld	(bc),a
} by {
	ld	(hl),a
	ld	c,l
	ld	b,h
	; peephole 25b loaded a into (hl) instead of (bc)
}

replace restart {
	ld	a,#%1
	ld	(hl),a
} by {
	ld	(hl),#%1
	; peephole 25c loaded #%1 into (hl) directly
} if notUsed('a')

replace restart {
	ex	de, hl
	push	de
} by {
	; peephole 26 pushed hl directly instead of going through de.
	push	hl
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	l,%1
	ld	h,d
	push	hl
} by {
	; peephole 27 pushed de instead of hl removing a load.
	ld	e,%1
	push	de
} if notUsed('hl'), notUsed('e')

replace restart {
	ex	de, hl
	push	bc
	push	de
} by {
	; peephole 28 pushed hl directly instead of going through de.
	push	bc
	push	hl
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	l,c
	ld	h,b
	push	hl
} by {
	; peephole 29 pushed bc directly instead of going through hl.
	push	bc
} if notUsed('hl')

replace restart {
	ld	l,%1
	ld	h,b
	push	hl
} by {
	; peephole 30 pushed bc instead of hl removing a load.
	ld	c,%1
	push	bc
} if notUsed('hl'), notUsed('c')

replace restart {
	ld	c,l
	ld	b,h
	push	%1
	push	bc
} by {
	; peephole 31 pushed hl directly instead of going through bc.
	push	%1
	push	hl
} if notUsed('bc'), notSame(%1 'bc')

replace restart {
	pop	de
	ld	l, e
	ld	h, d
} by {
	; peephole 32 popped hl directly instead of going through de.
	pop	hl
} if notUsed('de')

replace restart {
	pop	bc
	ld	l, c
	ld	h, b
} by {
	; peephole 33 popped hl directly instead of going through bc.
	pop	hl
} if notUsed('bc')

replace restart {
	ld	%1 (ix), %2
	ld	%3, %1 (ix)
} by {
	; peephole 34 loaded %3 from %2 instead of going through %1 (ix).
	ld	%1 (ix), %2
	ld	%3, %2
}
// Don't need to check for volatile, since ix is used for the stack.

replace restart {
	ld	%1 (ix), a
	push	de
	ld	%2, %1 (ix)
} by {
	ld	%1 (ix), a
	push	de
	; peephole 34a loaded %2 from a instead of %1 (ix)
	ld	%2, a
}	

replace restart {
	push	af
	inc	sp
	ld	a,e
	push	af
	inc	sp
} by {
	; peephole 35 pushed de instead of pushing a twice.
	ld	d,a
	push	de
} if notUsed('d'), notUsed('a')

replace restart {
	push	af
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	; peephole 36 pushed de instead of pushing a twice.
	ld	d,a
	ld	e,#%1
	push	de
} if notUsed('de')

replace restart {
	push	af
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	; peephole 37 pushed bc instead of pushing a twice.
	ld	b,a
	ld	c,#%1
	push	bc
} if notUsed('bc')

replace restart {
	push	bc
	inc	sp
	push	de
	inc	sp
} by {
	ld	c, d
	; peephole 37a combined pushing of b and d.
	push	bc
} if notUsed('c')

replace restart {
	push	bc
	inc	sp
	ld	a, c
	push	af
	inc	sp
} by {
	push	bc
	ld	a, c
	; peephole 38 simplified pushing bc.
}

replace restart {
	push	de
	inc	sp
	ld	a, #%1
	push	af
	inc	sp
} by {
	ld	e, #%1
	push	de
	; peephole 39 simplified pushing de.
} if notUsed('e')

replace restart {
	ld	a,#%1
	ld	d,a
} by {
	; peephole 40 loaded #%1 into d directly instead of going through a.
	ld	d,#%1
} if notUsed('a')

replace restart {
	ld	%1,a
	ld	%2,%1
} by {
	; peephole 41 loaded %2 from a directly instead of going through %1.
	ld	%2,a
} if notUsed(%1)

replace restart {
	ld	a,%1 (%3)
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	; peephole 42 pushed %1 (%3), %2(%3) through hl instead of af.
	ld	h,%1 (%3)
	ld	l,%2 (%3)
	push	hl
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	c, l
	ld	b, h
	push	bc
} by {
	; peephole 43 pushed hl instead of bc.
	push	hl
} if notUsed('bc')

replace restart {
	ld	a, (hl)
	inc	hl
	ld	h, (hl)
	ld	l, a
	push	hl
} by {
	; peephole 43a pushed bc instead of hl.
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
} if notUsed('bc'), notUsed('hl')

replace restart {
	pop	%1
	push	%1
} by {
	; peephole 44 eleminated dead pop/push pair.
} if notUsed(%1)

replace restart {
	push	hl
	pop	bc
} by {
	ld	c, l
	ld	b, h
	; peephole 44a replaced push/pop pair by loads.
} if notUsed('hl')

replace restart {
	push	hl
	pop	de
} by {
	ld	e, l
	ld	d, h
	; peephole 44b replaced push/pop pair by loads.
} if notUsed('hl')

replace restart {
	ld	iy,#%1
	or	a,%2 (iy)
} by {
	; peephole 45 used hl instead of iy.
	ld	hl,#%1 + %2
	or	a,(hl)
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy,#%1
	ld	%2,%3 (iy)
} by {
	; peephole 46 used hl instead of iy.
	ld	hl,#%1 + %3
	ld	%2, (hl)
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy,#%1
	ld	h,%3 (iy)
} by {
	; peephole 46a used hl instead of iy.
	ld	hl,#%1 + %3
	ld	h, (hl)
} if notUsed('iy'), notUsed('l')

replace restart {
	ld	iy,#%1
	ld	%2 (iy), %3
} by {
	; peephole 46b used hl instead of iy.
	ld	hl,#%1 + %2
	ld	(hl), %3
} if notUsed('iy'), notUsed('hl'), notSame(%3 'h' 'l')

replace restart {
	ld	iy,#%1
	ld	%2,0 (iy)
	ld	%3,1 (iy)
} by {
	; peephole 47 used hl instead of iy.
	ld	hl,#%1
	ld	%2, (hl)
	inc	hl
	ld	%3, (hl)
} if notUsed('iy'), notUsed('hl'), operandsNotRelated(%2 'hl')

replace restart {
	ld	iy,#%1
	ld	%2 (iy),%3
	ld	l,%2 (iy)
} by {
	; peephole 48 used hl instead of iy.
	ld	hl,#%1 + %2
	ld	(hl),%3
	ld	l,(hl)
} if notUsed('iy'), notUsed('h')

replace restart {
	ld	iy,#%1
	ld	%2 (%3), %4
} by {
	; peephole 49 used hl instead of iy.
	ld	hl,#%1 + %2
	ld	(hl), %4
} if notUsed('iy'), notUsed('hl'), operandsNotRelated(%4 'hl')

replace restart {
	ld	iy,#%1
	bit	%2,%3 (iy)
} by {
	; peephole 49a used hl instead of iy.
	ld	hl,#%1+%3
	bit	%2, (hl)
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1
	add	iy, sp
	ld	%2, %3 (iy)
} by {
	; peephole 49b used hl instead of iy.
	ld	hl, #%1+%3
	add	hl, sp
	ld	%2, (hl)
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1
	add	iy, sp
	ld	%2, 0 (iy)
	ld	%3, 1 (iy)
} by {
	; peephole 49c used hl instead of iy.
	ld	hl, #%1
	add	hl, sp
	ld	%2, (hl)
	inc	hl
	ld	%3, (hl)
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1
	add	iy, sp
	ld	l, 0 (iy)
	ld	h, 1 (iy)
} by {
	; peephole 49d used hl instead of iy.
	ld	hl, #%1
	add	hl, sp
	ld	a, (hl)
	inc	hl
	ld	h, (hl)
	ld	l, a
} if notUsed('iy'), notUsed('a')

replace restart {
	ld	iy, #%1
	add	iy, sp
	ld	0 (iy), #%2
	ld	1 (iy), #%3
} by {
	; peephole 49e used hl instead of iy.
	ld	hl, #%1
	add	hl, sp
	ld	(hl), #%2
	inc	hl
	ld	(hl), #%3
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1+1
	ld	a, 1 (iy)
	or	a, 0 (iy)
} by {
	ld	hl, #%1
	ld	a, (hl)
	dec	hl
	or	a, (hl)
	; peephole 49f used hl instead of iy.
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1
	add	iy, sp
	ld	a, 1 (iy)
	or	a, 0 (iy)
} by {
	ld	hl, #%1+1
	add	hl, sp
	ld	a, (hl)
	dec	hl
	or	a, (hl)
	; peephole 49f' used hl instead of iy.
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1
	add	iy, sp
	bit	%2, %3 (iy)
} by {
	ld	hl, #%1+%3
	add	hl, sp
	bit	%2, (hl)
	; peephole 49g used hl instead of iy.
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy, #%1
	add	iy, sp
	or	a, %2 (iy)
} by {
	ld	hl, #%1+%2
	add	hl, sp
	or	a, (hl)
	; peephole 49h used hl instead of iy.
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	inc	bc
} by {
	; peephole 51 incremented in hl instead of bc.
	inc	hl
	ld	c,l
	ld	b,h
} if notUsed('hl')

replace restart {
	ld	iy, #%1
	inc	%2 (iy)
} by {
	; peephole 51a incremented in (hl) instead of %2 (iy).
	ld	hl, #%1+%2
	inc	(hl)
} if notUsed('hl'), notUsed('iy')

replace restart {
	ld	iy, #%1
	dec	%2 (iy)
} by {
	; peephole 51a' decremented in (hl) instead of %2 (iy).
	ld	hl, #%1+%2
	dec	(hl)
} if notUsed('hl'), notUsed('iy')

replace restart {
	add	hl, hl
	ld	e, l
	ld	d, h
	inc	de
	inc	de
} by {
	inc	hl
	; peephole 51b incremented once in hl instead of incrementing in de twice.
	add	hl, hl
	ld	e, l
	ld	d, h
} if notUsed('hl')

replace restart {
	add	hl, hl
	inc	hl
	inc	hl
} by {
	inc	hl
	; peephole 51c incremented once in hl instead of incrementing in hl twice.
	add	hl, hl
}

replace restart {
	add	a, a
	add	a, a
	add	a, #0x04
} by {
	inc	a
	; peephole 51d incremented a once instead of adding #0x04 to a.
	add	a, a
	add	a, a
}

replace restart {
	add	hl, hl
	pop	de
	inc	hl
	inc	hl
} by {
	inc	hl
	; peephole 51e incremented once in hl instead of incrementing in hl twice.
	add	hl, hl
	pop	de
}

replace restart {
	ld	a,%1 (%2)
	bit	%3,a
} by {
	; peephole 52 tested bit of %1 (%2) directly instead of going through a.
	bit	%3,%1 (%2)
} if notUsed('a')

replace restart {
	ld	a,%1
	bit	%2,a
} by {
	; peephole 53 tested bit %2 of %1 directly instead of going through a.
	bit	%2,%1
} if notUsed('a'), canAssign(%1 'b')

replace restart {
	ld	a, %1
	set	%2, a
	ld	%1, a
} by {
	; peephole 54 set bit %2 of %1 directly instead of going through a.
	set	%2, %1
	ld	a, %1
} if canAssign(%1 'b')
// canAssign(%1 'b') is true, iff set b, %1 is possible.

replace restart {
	ld	a, %1 (%2)
	set	%3, a
	ld	%1 (%2), a
} by {
	; peephole 55 set bit %3 of %1 (%2) directly instead of going through a.
	set	%3, %1 (%2)
	ld	a, %1 (%2)
}

replace restart {
	ld	a, %1
	res	%2, a
	ld	%1, a
} by {
	; peephole 56 reset bit %2 of %1 directly instead of going through a.
	res	%2, %1
	ld	a, %1
} if canAssign(%1 'b')
// canAssign(%1 'b') is true, iff set b, %1 is possible.

replace restart {
	ld	a, %1 (%2)
	res	%3, a
	ld	%1 (%2), a
} by {
	; peephole 57 reset bit %3 of %1 (%2) directly instead of going through a.
	res	%3, %1 (%2)
	ld	a, %1 (%2)
}

replace restart {
	ld	c, %1 (%2)
	ld	b, %3 (%4)
	ld	l,c
	ld	h,b
} by {
	; peephole 58 stored %1 (%2) %3 (%4) into hl directly instead of going through bc.
	ld	l, %1 (%2)
	ld	h, %3 (%4)
} if notUsed('bc')

replace restart {
	ld	c, %1
	ld	b, %2
	ld	l,c
	ld	h,b
} by {
	; peephole 59 stored %2%1 into hl directly instead of going through bc.
	ld	l, %1
	ld	h, %2
} if notUsed('bc'), operandsNotRelated(%2 'l')

replace restart {
	jp	NC,%1
	jp	%2
%1:
} by {
	jp	C,%2
	; peephole 60 removed jp by using inverse jump logic
%1:
} if labelRefCountChange(%1 -1)

replace restart {
	jp	C,%1
	jp	%2
%1:
} by {
	jp	NC,%2
	; peephole 61 removed jp by using inverse jump logic
%1:
} if labelRefCountChange(%1 -1)

replace restart {
	jp	NZ,%1
	jp	%2
%1:
} by {
	jp	Z,%2
	; peephole 62 removed jp by using inverse jump logic
%1:
} if labelRefCountChange(%1 -1)

replace restart {
	jp	Z,%1
	jp	%2
%1:
} by {
	jp	NZ,%2
	; peephole 63 removed jp by using inverse jump logic
%1:
} if labelRefCountChange(%1 -1)

replace restart {
	jp	%5
} by {
	jp	%6
	; peephole 64 jumped to %6 directly instead of via %5.
} if labelIsUncondJump(), notSame(%5 %6), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)

replace restart {
	jp	%1,%5
} by {
	jp	%1,%6
	; peephole 65 jumped to %6 directly instead of via %5.
} if labelIsUncondJump(), notSame(%5 %6), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)

replace restart {
	jp	%1
%2:
%1:
} by {
   ; peephole 65a eliminated jump.
%2:
%1:
} if labelRefCountChange(%1 -1)

// A peephole that makes the code longer. Let's hope it's worth it in speed gain and further optimization potential.
replace restart {
	ld	a,#0x00
%1:
	bit	%2,a
	jp	Z,%3
} by {
	ld	a,#0x00
	jp	%3
	; peephole 65a jumped directly to %3 instead of testing a first.
%1:
	bit	%2,a
	jp	Z,%3
} if labelRefCountChange(%3 +1)

replace restart {
	ld	%1, %2
	jp	%3
	jp	%4
} by {
	ld	%1, %2
	jp	%3
	; peephole 65b removed unreachable jump to %3.
}

replace restart {
	ld	%1, %2
	jp	%3
%3:
} by {
	ld	%1, %2
%3:
	; peephole 65c removed redundant jump to %3.
} if labelRefCountChange(%3 -1)

replace restart {
	ld	%1, #0x01
	bit	0, %1
	jp	Z, %2
} by {
	ld	%1, #0x01
	; peephole 65d removed impossible jump to %2.
} if labelRefCountChange(%2 -1)

replace restart {
	rlca
	and	a, #0x01
	jp	Z, %1
} by {
	rlca
	; peephole 65e removed and by changing jump condition.
	jp	NC, %1
} if notUsed('a'), notUsedFrom(%1 'a')

replace restart {
	rlca
	and	a, #0x01
	jp	NZ, %1
} by {
	rlca
	; peephole 65f removed and by changing jump condition.
	jp	C, %1
} if notUsed('a'), notUsedFrom(%1 'a')

replace restart {
	xor	a,a
	ld	a,#0x00
} by {
	xor	a,a
	; peephole 66 removed redundant load of 0 into a.
}

replace restart {
	ld	e,#0x%1
	ld	d,#0x%2
} by {
	ld	de,#0x%2%1
	; peephole 67 combined constant loads into register pair.
}

replace restart {
	ld	d,#0x%1
	ld	e,#0x%2
} by {
	ld	de,#0x%1%2
	; peephole 67a combined constant loads into register pair.
}

replace restart {
	ld	l,#0x%1
	ld	h,#0x%2
} by {
	ld	hl,#0x%2%1
	; peephole 68 combined constant loads into register pair.
}

replace restart {
	ld	h,#0x%1
	ld	l,#0x%2
} by {
	ld	hl,#0x%1%2
	; peephole 68a combined constant loads into register pair.
}

replace restart {
	ld	c,#0x%1
	ld	b,#0x%2
} by {
	ld	bc,#0x%2%1
	; peephole 69 combined constant loads into register pair.
}

replace restart {
	ld	b,#0x%1
	ld	c,#0x%2
} by {
	ld	bc,#0x%1%2
	; peephole 69a combined constant loads into register pair.
}

replace restart {
	ld	%1,a
	ld	a,%1
} by {
	ld	%1,a
	; peephole 70 removed redundant load from %1 into a.
} if notVolatile(%1)
// This gives many false negatives and without the test no problems are encountered in the regression tests
// Maybe we can try this after 2.7.0 release

replace restart {
	ld	a,%1
	ld	%1,a
} by {
	ld	a,%1
	; peephole 71 removed redundant load from a into %1.
} if notVolatile(%1)
// This gives many false negatives and without the test no problems are encountered in the regression tests
// Maybe we can try this after 2.7.0 release

replace restart {
	ld	%1,a
	ld	a,%2
	or	a,%1
} by {
	ld	%1,a
	or	a,%2
	; peephole 72 removed load by reordering or arguments.
} if notVolatile(%1), canAssign('b' %2)
// canAssign('b' %2) is true, iff or a,%2 is possible.

replace restart {
	or	a,%1
	or	a,a
} by {
	or	a,%1
	; peephole 73 removed redundant or after or.
}

replace restart {
	or	a,%1 (%2)
	or	a,a
} by {
	or	a,%1 (%2)
	; peephole 74 removed redundant or after or.
}

replace restart {
	and	a,%1
	or	a,a
} by {
	and	a,%1
	; peephole 75 removed redundant or after and.
}

replace restart {
	xor	a,%1
	or	a,a
} by {
	xor	a,%1
	; peephole 76 removed redundant or after xor.
}

replace restart {
	xor	a,%1 (%2)
	or	a,a
} by {
	xor	a,%1 (%2)
	; peephole 77 removed redundant or after xor.
}

replace restart {
	ld	%1,%2
	ld	a,%2
} by {
	ld	a,%2
	ld	%1,a
	; peephole 78 load value in a first and use it next
} if notVolatile(%1 %2)

replace restart {
	ld	%1,%2
	ld	%3,%4
	ld	%2,%1
	ld	%4,%3
} by {
	ld	%1,%2
	ld	%3,%4
	; peephole 79 removed redundant load from %3%1 into %4%2
} if notVolatile(%1 %2 %3 %4)

replace restart {
	push	de
	inc	sp
	ld	a,e
	push	af
	inc	sp
} by {
	push	de
	; peephole 80 pushed de
} if notUsed('a')

replace restart {
	ld	iy,%1
	add	iy,sp
	ld	sp,iy
} by {
	ld	hl,%1
	add	hl,sp
	ld	sp,hl
	; peephole 81 fixed stack using hl instead of iy.
} if notUsed('hl'), notUsed('iy')

replace restart {
	ld	a,%1
	sub	a,%2
	jp	%3,%4
	ld	a,%1
} by {
	ld	a,%1
	cp	a,%2
	jp	%3,%4
	; peephole 82 removed load from %1 into a by replacing sub with cp
	assert	a=%1
} if notVolatile(%1), notUsedFrom(%4 'a')

replace restart {
	assert	a=%1
	sub	a,%2
	jp	%3,%4
	ld	a,%1
} by {
	cp	a,%2
	jp	%3,%4
	; peephole 83 removed load from %1 into a by replacing sub with cp
	assert	a=%1
} if notUsedFrom(%4 'a')

replace restart {
	assert	a=%1
} by {
}

replace restart {
	sub	a,#0xFF
	jp	Z,%1
} by {
	inc	a
	; peephole 84 replaced sub a,#0xFF by inc a.
	jp	Z,%1
}

replace restart {
	sub	a,#0xFF
	jp	NZ,%1
} by {
	inc	a
	; peephole 85 replaced sub a,#0xFF by inc a.
	jp	NZ,%1
}

replace restart {
	rlca
	ld	a,#0x00
	rla
} by {
	rlca
	and	a,#0x01
	; peephole 86 replaced zero load, rla by and since rlca writes the same value to carry bit and least significant bit.
}

replace restart {
	ld	%1,%2
	push	%1
	pop	%4
	ld	%1,%3
} by {
	ld	%4,%2
	; peephole 87 moved %2 directly into de instead of going through %1.
	ld	%1,%3
}

replace restart {
	add	a,#0x00
	ld	%2,a
	ld	a,%3
	adc	a,%4
} by {
	; peephole 88 removed lower part of multibyte addition.
	ld	%2,a
	ld	a,%3
	add	a,%4
}

replace restart {
	ld	a, l
	add	a, #0x%1
	ld	e, a
	ld	a, h
	adc	a, #0x%2
	ld	d, a
} by {
	ld	de, #0x%2%1
	add	hl, de
	; peephole 89 used 16-bit addition.
	ld	e, l
	ld	d, h
	ld	a, h
} if notUsed('hl')

replace restart {
	ld	a, l
	add	a, #0x%1
	ld	c, a
	ld	a, h
	adc	a, #0x%2
	ld	b, a
} by {
	ld	bc, #0x%2%1
	add	hl,bc
	; peephole 90 used 16-bit addition.
	ld	c, l
	ld	b, h
	ld	a, h
} if notUsed('hl')

replace restart {
	ld	%1,a
	ld	a,%2
	add	a,%1
} by {
	; peephole 91 removed loads by exploiting commutativity of addition.
	add	a,%2
} if notVolatile(%1), notUsed(%1), canAssign('b' %2)
// canAssign('b' %2) is true, iff add a,%2 is possible.

replace restart {
	ld	%1 (ix),a
	ld	a,#%2
	add	a,%1 (ix)
} by {
	ld	%1 (ix),a
	; peephole 92 removed loads by exploiting commutativity of addition.
	add	a,#%2
}
// Don't need to check for volatile, since ix is used to access the stack.

replace restart {
	ld	l,%1 (ix)
	ld	h,%2 (ix)
	ld	a,(hl)
	inc	a
	ld	l,%1 (ix)
	ld	h,%2 (ix)
	ld	(hl),a
} by {
	ld	l,%1 (ix)
	ld	h,%2 (ix)
	inc	(hl)
	; peephole 93 incremented in (hl) instead of going through a.
} if notUsed('a')

replace restart {
	ld	a,(hl)
	inc	a
	ld	(hl),a
} by {
	inc	(hl)
	; peephole 93' incremented in (hl) instead of going through a.
} if notUsed('a')

// TODO: Check for volatile?
replace restart {
	ld	%1, %2 (%3)
	inc	%1
	ld	%2 (%3), %1
} by {
	inc	%2 (%3)
	ld	%1, %2 (%3)
	; peephole 93a incremented in %2 (%3) instead of going through %1.
}

// TODO: Check for volatile?
replace restart {
	ld	%1, %2 (%3)
	dec	%1
	ld	%2 (%3), %1
} by {
	dec	%2 (%3)
	ld	%1, %2 (%3)
	; peephole 93b decremented in %2 (%3) instead of going through %1.
}

replace restart {
	ld	%1,a
	ld	a,%2
	add	a,%1
} by {
	ld	%1, a
	; peephole 94 removed load by exploiting commutativity of addition.
	add	a,%2
} if notSame(%2 '(bc)' '(de)'), canAssign('b' %2)
// canAssign('b' %2) is true, iff add a,%2 is possible.

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	add	hl,bc
} by {
	; peephole 95 removed loads by exploiting commutativity of addition.
	ld	bc,#%1
	add	hl,bc
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	add	hl,%2
	ld	bc,#%4
	add	hl,bc
} by {
	; peephole 96 removed loads by exploiting commutativity of addition.
	ld	hl,#%1 + %4
	add	hl,%2
} if notUsed('bc')

replace restart {
	ld	c,e
	ld	b,d
	ld	hl,#%1
	add	hl,bc
} by {
	; peephole 97 removed loads by exploiting commutativity of addition.
	ld	hl,#%1
	add	hl,de
} if notUsed('bc')

replace restart {
	or	a,%1
	jp	NZ,%2
	ld	%3,#0x00
} by {
	or	a,%1
	jp	NZ,%2
	ld	%3,a
	; peephole 98 replaced constant #0x00 by a (which has just been tested to be #0x00).
}

replace restart {
	and	a,%1
	jp	NZ,%2
	ld	%3,#0x00
} by {
	and	a,%1
	jp	NZ,%2
	ld	%3,a
	; peephole 99 replaced constant #0x00 by a (which has just been tested to be #0x00).
}

replace restart {
	sub	a,%1
	jp	NZ,%2
	ld	%3,#0x00
} by {
	sub	a,%1
	jp	NZ,%2
	ld	%3,a
	; peephole 100 replaced constant #0x00 by a (which has just been tested to be #0x00).
}

replace restart {
	inc	a
	jp	NZ,%1
	ld	%2,#0x00
} by {
	inc	a
	jp	NZ,%1
	ld	%2,a
	; peephole 101 replaced constant #0x00 by a (which has just been tested to be #0x00).
}

replace restart {
	dec	a
	jp	NZ,%1
	ld	%2,#0x00
} by {
	dec	a
	jp	NZ,%1
	ld	%2,a
	; peephole 102 replaced constant #0x00 by a (which has just been tested to be #0x00).
}

replace restart {
	or	a,%1
	jp	NZ,%2
	ld	a,%3
	or	a,a
} by {
	or	a,%1
	jp	NZ,%2
	or	a,%3
	; peephole 103 shortened or using a (which has just been tested to be #0x00).
} if canAssign('b' %3)
// canAssign('b' %2) is true, iff or a,%2 is possible.

replace restart {
	sub	a,%1
	jp	NZ,%2
	ld	a,%3
	or	a,a
} by {
	sub	a,%1
	jp	NZ,%2
	or	a,%3
	; peephole 104 shortened or using a (which has just been tested to be #0x00).
} if canAssign('b' %3)
// canAssign('b' %2) is true, iff or a,%2 is possible.

replace restart {
	or	a,%1
	jp	NZ,%2
	push	%3
	ld	%4,#0x00
} by {
	or	a,%1
	jp	NZ,%2
	push	%3
	ld	%4,a
	; peephole 105 replaced constant #0x00 by a (which has just been tested to be #0x00).
}

replace restart {
	ld	(hl),#0x00
	inc	hl
	ld	(hl),#0x00
} by {
	xor	a, a
	; peephole 106 cached zero in a.
	ld	(hl), a
	inc	hl
	ld	(hl), a
} if notUsed('a')

replace restart {
	ld	hl,#%1
	add	hl,%2
	inc	hl
} by {
	ld	hl,#%1+1
	add	hl,%2
	; peephole 107 moved increment of hl to constant.
}

replace restart {
	inc	hl
	ld	%1,#%2
	add	hl,%1
} by {
	ld	%1,#%2+1
	add	hl,%1
	; peephole 108 moved increment of hl to constant.
} if notUsed(%1)

replace restart {
	dec	hl
	ld	%1,#%2
	add	hl,%1
} by {
	ld	%1,#%2-1
	add	hl,%1
	; peephole 109 moved decrement of hl to constant.
} if notUsed(%1)

replace restart {
	inc	iy
	ld	%1, %2 (iy)
} by {
	ld	%1, %2+1 (iy)
	; peephole 110 moved increment of iy to offset.
} if notUsed('iy')

replace restart {
	push	hl
	pop	iy
	pop	hl
	inc	iy
} by {
	inc	hl
	push	hl
	pop	iy
	pop	hl
	; peephole 111 incremented in hl instead of iy.
}

replace restart {
	push	hl
	pop	iy
	inc	iy
} by {
	inc	hl
	push	hl
	pop	iy
	; peephole 111a incremented in hl instead of iy.
} if notUsed('hl')

replace restart {
	push	bc
	pop	iy
	inc	iy
} by {
	inc	bc
	push	bc
	pop	iy
	; peephole 111b incremented in bc instead of iy.
} if notUsed('bc')

replace restart {
	push	de
	pop	iy
	inc	iy
} by {
	inc	de
	push	de
	pop	iy
	; peephole 111c incremented in de instead of iy.
} if notUsed('de')

replace restart {
	ld	hl,%1
	add	hl,%2
	push	hl
	pop	iy
} by {
	ld	iy,%1
	add	iy,%2
	; peephole 111b added in iy instead of hl.
} if notUsed('hl'), notSame(%2 'hl')

replace restart {
	pop	af
	ld	sp,%1
} by {
	; peephole 112 removed redundant pop af.
	ld	sp,%1
} if notUsed('a')

replace restart {
	inc	sp
	ld	sp,%1
} by {
	; peephole 113 removed redundant inc sp.
	ld	sp,%1
} if notUsed('a')

replace restart {
	call    %1
	ret
} by {
	jp  %1
	; peephole 114 replaced call at end of function by jump (tail call optimization).
} if symmParmStack(%1)

// Callee saves ix.
replace restart {
	call	%1
	pop	ix
	ret
} by {
	pop	ix
	jp	%1
	; peephole115 replaced call at end of function by jump moving call beyond pop ix (tail call optimization).
} if symmParmStack(%1), notSame(%1 '____sdcc_cpu_pop_ei'), notSame(%1 '___sdcc_enter_ix')

replace restart {
	ld	%1,#%2
	ld	%3,%4
	ld	%1,#%2
} by {
	ld	%1,#%2
	ld	%3,%4
	; peephole 116 removed load of #%2 into %1 since it's still there.
} if notVolatile(%1), operandsNotRelated(%3 %1)

replace restart {
	ld	hl,#%1
	ld	de,#%1
} by {
	; peephole 117 used #%1 from hl for load into de.
	ld	hl,#%1
	ld	e,l
	ld	d,h
}

replace restart {
	ld	%1 (ix),l
	ld	%2 (ix),h
	ld	%3,%1 (ix)
	ld	%4,%2 (ix)
} by {	
	ld	%1 (ix),l
	ld	%2 (ix),h
	; peephole 118 used hl instead of %2 (ix), %1 (ix) to load %4%3.
	ld	%3,l
	ld	%4,h
} if operandsNotRelated('h' %3)
// Don't check for volatile since ix points to the stack.

replace restart {
	ld	%1, a
	ld	a, %2 (%3)
	adc	a, #%4
	ld	%6, %1
} by {
	ld	%6, a
	ld	a, %2 (%3)
	adc	a, #%4
	; peephole 119 loaded %6 from a directly instead of going through %1.
} if notUsed(%1), notSame(%6 'a')

replace restart {
	ld	%1, a
	ld	a, %2 (%3)
	adc	a, #%4
	ld	%5, a
	ld	%6, %1
} by {
	ld	%6, a
	ld	a, %2 (%3)
	adc	a, #%4
	ld	%5, a
	; peephole 120 loaded %6 from a directly instead of going through %1.
} if notUsed(%1), notSame(%5 %1), notSame(%5 '(hl)' '(de)' '(bc)'), notSame(%5 %6), notSame(%6 '(hl)' '(de)' '(bc)'), notSame(%5 'a'), notSame(%6 'a')

replace restart {
	ld	%1, a
	ld	a, #%2
	adc	a, #%3
	ld	%5, a
	ld	%6, %1
} by {
	ld	%6, a
	ld	a, #%2
	adc	a, #%3
	ld	%5, a
	; peephole 121 loaded %6 from a directly instead of going through %1.
} if notUsed(%1), notSame(%5 %1), notSame(%5 %6 '(hl)' '(de)' '(bc)'), notSame(%6 'a')

replace restart {
	ld	hl, #%1
	add	hl, %2
	ex	de, hl
	ld	hl, #%3
	add	hl, de
} by {
	ld	hl, #%1+%3
	add	hl, %2
	; peephole 122 removed addition and loads exploiting commutativity of addition.
} if notUsed('de')

replace restart {
	ld	%1,l
	ld	%2,h
	ex	de,hl
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
} by {
	ld	%1,l
	ex	de,hl
	; peephole 122a used de instead of going through %1%2.
	ld	(hl),e
	inc	hl
	ld	(hl),d
} if notUsed(%2), notSame(%1 'l' 'h' 'e' 'd'), notSame(%2 'l' 'h' 'e' 'd')
	
replace restart {
	ld	e, l
	ld	d, h
	ld	hl, #0x0001
	add	hl, de
} by {
	ld	e, l
	ld	d, h
	inc	hl
	; peephole 123 replaced addition by increment.
}

replace restart {	
	ld      sp,hl
	ld      hl,#0x0002
	add     hl,sp
} by {
	ld	sp, hl
	inc	hl
	inc	hl
	; peephole 124 replaced addition by increment.
}

replace restart {
	ex	de, hl
	ld	hl, #%1
	add	hl, de
} by {
	; peephole 125 removed ex exploiting commutativity of addition.
	ld	de, #%1
	add	hl, de
} if notUsed('de')

replace restart {
	ex	de, hl
	push	bc
	ex	de, hl
} by {
	push	bc
	; peephole 126 canceled subsequent ex de, hl.
}

replace restart {
	ld	hl, #%1
	add	hl, %2
	ex	de, hl
	inc	de
} by {
	ld	hl, #%1+1
	; peephole 127 moved increment to constant.
	add	hl, %2
	ex	de, hl
} if notUsed('hl')

replace restart {
	ld	a,#0x01
	jp	%1
%2:
	xor	a,a
%1:
	sub	a,#0x01
	ld	a,#0x00
	rla
} by {
	xor	a,a
	jp	%1
%2:
	ld	a,#0x01
%1:
	; peephole 128 removed negation.
} if labelRefCount(%1 1)

replace restart {
	and	a,#0x01
	sub	a,#0x01
	ld	a,#0x00
	rla
} by {
	and	a,#0x01
	xor	a,#0x01
	; peephole 129 used xor for negation.
}

replace restart {
	or	a,a
	sub	a,#%1
} by {
	; peephole 130 removed redundant or.
	sub	a,#%1
}

replace restart {
	ld	a,#0x00
	rla
	sub	a,#0x01
	ld	a,#0x00
	rla
} by {
	ld	a,#0x00
	ccf
	; peephole 131 moved negation from bit 0 to carry flag.
	rla
}

replace restart {
	ld	a, #<(%1)
	add	a, l
	ld	l, a
	ld	a, #>(%1)
	adc	a, h
	ld	h, a
	push	bc
} by {
	push	bc
	ld	bc, #%1
	add	hl, bc
	; peephole 132 used 16 bit addition by moving push bc
	ld	a, h
} if notUsed('bc')

replace restart {
	pop	af
	push	hl
} by {
	; peephole 133 used ex to move hl onto the stack.
	ex	(sp),hl
} if notUsed('a'), notUsed('hl')

replace restart {
	pop	af
	ld	hl, #%1
	push	hl
} by {
	ld	hl, #%1
	; peephole 134 used ex to move hl onto the stack.
	ex	(sp),hl
} if notUsed('a'), notUsed('hl')

replace restart {
	pop	af
	inc	sp
	ld	hl,#%1
	push	hl
} by {
	inc	sp
	ld	hl,#%1
	; peephole 135 used ex to move #%1 onto the stack.
	ex	(sp),hl
} if notUsed('a'), notUsed('hl')

replace restart {
	pop	af
	ld	a,#%1
	push	af
	inc	sp
} by {
	ld	h,#%1
	ex	(sp),hl
	; peephole 136 used ex to move #%1 onto the stack.
	inc	sp
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	%1,#%2
	ld	%3 (%1),a
%4:
	ld	%1,%5
} by {
	ld	(#%2 + %3),a
	; peephole 137 directly used #%2 instead of going through %1 using indirect addressing.
%4:
	ld	%1,%5
}

replace restart {
	pop	af
	ld	%1,#%2
	ld	%3 (%1),%4
	ld	%1,#%5
} by {
	ld	a,%4
	ld	(#%2 + %3),a
	; peephole 138 used #%2 directly instead of going through %1 using indirect addressing.
	pop	af
	ld	%1,#%5
} if notSame(%3 'a')

replace restart {
	ld	%1,a
	bit	%2,%1
} by {
	bit	%2,a
	; peephole 139 tested bit %2 of a directly instead of going through %1.
} if notUsed(%1)

replace restart {
	sbc	a,%1
	bit	7,a
	jp	Z,%2
} by {
	sbc	a,%1
	jp	P,%2
	; peephole 140 used sign flag instead of testing bit 7.
}

replace restart {
	sbc	a,%1
	bit	7,a
	jp	NZ,%2
} by {
	sbc	a,%1
	jp	M,%2
	; peephole 141 used sign flag instead of testing bit 7.
}

replace restart {
	dec %1
	ld	a, %1
	or	a, a
} by {
	dec %1
	; peephole 141a removed redundant transfer and flag setting in a
} if notUsed('a')

replace restart {
	ld	%1,a
	or	a,a
	jp	%3,%4
	ld	a,%1
} by {
	ld	%1,a
	or	a,a
	jp	%3,%4
	; peephole 142 used value still in a instead of reloading from %1.
}

replace restart {
	jp	%5
	ret
} by {
	jp	%5
	; peephole 143 removed unused ret.
}

replace restart {
	jp	%5
	ld	sp,ix
	pop	ix
	ret
} by {
	jp	%5
	; peephole 144 removed unused ret.
}

replace restart {
	or	a,%1
	jp	NZ,%2
	xor	a,a
	jp	%3
} by {
	or	a,%1
	jp	NZ,%2
	; peephole 145 removed redundant zeroing of a (which has just been tested to be #0x00).
	jp	%3
}


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Z88DK SPECULATIVE SUBSTITUTIONS APPLIED TO SDCC FOR #9477
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	de,#%2
	ld	bc,#%3
	dec	hl
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	push	hl
	ld	hl,#%1
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	push	hl
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	push	de
	push	hl
	ld	a,l
	ld	de,#%2
	ld	bc,#%3
	; peephole z88dk-1a  Replace Monolithic Block
}
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	dec	hl
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
	ld	hl,#%1
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	push	de
	push	hl
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-1b  Replace Monolithic Block
}
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	de,#%2
	dec	hl
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
	ld	hl,#%1
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	push	hl
	push	de
} by {
	ld	c,e
	ld	b,d
	ld	a,l
	ld	(#%1),hl
	ld	(#%1 + 2),de
	push	de
	push	hl
	ld	de,#%2
	push	de
	; peephole z88dk-1c  Replace Monolithic Block
}
// if notVolatile

replace restart {
	ld	hl,#%1
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
	inc	hl
	ld	(hl),#0x%2
	inc	hl
	ld	(hl),#0x%3
} by {
	ld	hl,#0x0000
	ld	a,l
	ld	(#%1),hl
	ld	hl,#0x%3%2
	ld	(#%1 + 2),hl
	; peephole z88dk-4  Store 2x16bit statics
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
} by {
	ld	hl,(#%1)
	push	hl
	ld	hl,#%1 + 1
	; peephole z88dk-5a  Use hl to load parameter from memory
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	ld	e, (hl)
	inc	hl
	ld	d, (hl)
	push	de
} by {
	ld	hl,(#%1)
	push	hl
	ld	hl,#%1 + 1
	; peephole z88dk-5b  Use hl to load parameter from memory
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
} by {
	ld	hl,(#%1)
	ld	a,l
	; peephole z88dk-6a  Load 16-bit static directly through hl
} 

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
} by {
	ld	hl,(#%1 + %2)
	ld	a,l
	; peephole z88dk-6b  Load 16-bit static directly through hl
}

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	; peephole z88dk-8a  Copy bytes using 16-bit ops
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	ex	de,hl
	; peephole z88dk-8b  Copy bytes using 16-bit ops
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
} by {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	pop	hl
	; peephole z88dk-8c  Copy bytes using 16-bit ops
}

replace restart {
	ld	a,(#%1 + 2)
	ld	(#%2 + 2),a
	ld	a,(#%1 + 3)
	ld	(#%2 + 3),a
} by {
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	a,h
	; peephole z88dk-8d  Copy bytes using 16-bit ops
} if notUsed('hl')

replace restart {
	ld	a,(#%1 + 2)
	ld	(#%2 + 2),a
	ld	a,(#%1 + 3)
	ld	(#%2 + 3),a
} by {
	ex	de,hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	a,h
	ex	de,hl
	; peephole z88dk-8e  Copy bytes using 16-bit ops
} if notUsed('de')

replace restart {
	ld	a,(#%1 + 2)
	ld	(#%2 + 2),a
	ld	a,(#%1 + 3)
	ld	(#%2 + 3),a
} by {
	push	hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	a,h
	pop	hl
	; peephole z88dk-8f  Copy bytes using 16-bit ops
}

replace restart {
	ld	d,l
	ld	e,h
	ld	hl,#%1
	ld	(hl),d
	inc	hl
	ld	(hl),e
	dec	hl
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
} by {
	ld	(#%1),hl
	push	hl
	ld	c,l
	ld	b,h
	ld	d,l
	ld	e,h
	ld	hl,#%1 + 1
	; peephole z88dk-9  Store hl to memory directly
} 
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	dec	hl
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
	ld	hl,(#%1)
	push	hl
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	push	de
	push	hl
	ld	c,e
	ld	b,d
	; peephole z88dk-10  Store dehl to memory directly
} 
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	ld	b,l
	ld	c,h
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ld	hl,#%1 + 3
	; peephole z88dk-11  Store dehl to memory directly
} 

replace restart {
	ld	d,l
	ld	e,h
	ld	hl,#%1
	ld	(hl),d
	inc	hl
	ld	(hl),e
	ld	de,#%2
	dec	hl
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
} by {
	ld	(#%1),hl
	push	hl
	ld	c,l
	ld	b,h
	ld	de,#%2
	ld	hl,#%1 + 1
	; peephole z88dk-11.5  Store hl to memory directly
}
// if notVolatile

replace restart {
	ld	d,l
	ld	e,h
	ld	hl,#%1
	ld	(hl),d
	inc	hl
	ld	(hl),e
} by {
	ld	(#%1),hl
	ld	d,l
	ld	e,h
	ld	hl,#%1 + 1
	; peephole z88dk-12  Store hl to memory directly
} 

replace restart {
	ld	hl,#%1 + 0
	ld	(hl), #0x%2
	ld	hl,#%1 + 1
	ld	(hl), #0x%3
	ld	hl,#%1 + 2
	ld	(hl), #0x%4
	ld	hl,#%1 + 3
	ld	(hl), #0x%5
} by {
	ld	hl,#0x%3%2
	ld	(#%1),hl
	ld	hl,#0x%5%4
	ld	(#%1 + 2),hl
	ld	hl,#%1 + 3
	; peephole z88dk-13  Write 32-bit static with 16-bit stores
}

replace restart {
	ld	hl,#%1 + 0
	ld	(hl), #0x%2
	ld	hl,#%1 + 1
	ld	(hl), #0x%3
} by {
	ld	hl,#0x%3%2
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-14  Write 16bit static with 16bit store
} 

replace restart {
	ex	de, hl
	push	hl
	push	de
} by {
	push	de
	push	hl
	; peephole z88dk-15  Eliminate unnecessary 'ex de,hl'
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	iy,#0
	add	iy,sp
	ld	3 (iy),d
	ld	2 (iy),e
	ld	1 (iy),h
	ld	0 (iy),l
	ld	de, #%1
	ld	hl, #0
	add	hl, sp
	ld	bc, #4
	ldir
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	; peephole z88dk-16  Write long static using 16bit stores instead of iy indexing
} if notUsed('bc'), notUsed('de'), notUsed('hl'), notUsed('iy')

replace restart {
	ld	de, #%1
	ld	hl, #0
	add	hl, sp
	ld	bc, #4
	ldir
} by {
	pop	hl
	pop	de
	ld	(#%1),hl
	ld	(#%1 + 2),de
	push	de
	push	hl
	; peephole z88dk-17  Replace ldir of long from top of stack with 16bit stores
} if notUsed('bc'), notUsed('de'), notUsed('hl')

replace restart {
	ld	de, #%1
	ld	hl, #%2
	ld	bc, #4
	ldir
} by {
	ld	hl,(#%2)
	ld	(#%1),hl
	ld	hl,(#%2 + 2)
	ld	(#%1 + 2),hl
	; peephole z88dk-18  Replace ldir used to copy long with 16bit loads and stores
} if notUsed('bc'), notUsed('de'), notUsed('hl')

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ld	b,l
	ld	c,h
	ld	hl,#%1 + 3
	; peephole z88dk-19  Write long static using 16bit stores
}

replace restart {
	ex	de, hl
	ld	bc,#%1
	push	hl
	push	de
} by {
	ld	bc,#%1
	push	de
	push	hl
	; peephole z88dk-20  Eliminate unnecessary 'ex de,hl'
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	ld	bc,#%0
	push	de
} by {
	ld	bc,#%0
	push	hl
	; peephole z88dk-21  Eliminate unnecessary 'ex de,hl'
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	l, c
	ld	h, b
	ld	(#%1),hl
} by {
	ld	(#%1),bc
	; peephole z88dk-23  Write bc to memory directly rather than first loading into hl
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),#0x%2
	inc	hl
	ld	(hl),#0x%3
	inc	hl
	ld	(hl),#0x%4
	inc	hl
	ld	(hl),#0x%5
} by {
	ld	hl,#0x%3%2
	ld	(#%1),hl
	ld	hl,#0x%5%4
	ld	(#%1 + 2),hl
	ld	hl,#%1 + 3
	; peephole z88dk-24  Write 32bit const using 16bit stores
}

replace restart {
	ld	hl,#%1
	ld	(hl),#0x%2
	inc	hl
	ld	(hl),#0x%3
} by {
	ld	hl,#0x%3%2
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-25  Write 16bit const using 16bit store
}

replace restart {
	ld	c,l
	ld	b,h
	ld	de,#%1
	push	bc
} by {
	ld	de,#%1
	push	hl
	; peephole z88dk-26  Eliminate unnecessary load of hl into bc
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
	inc	hl
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
} by {
	ld	hl,#0x0000
	ld	a,l
	ld	(#%1),hl
	ld	(#%1 + 2),hl
	ld	hl,#%1 + 3
	; peephole z88dk-27  Write 0s using 16bit stores
} 

replace restart {
	ld	hl,#%1
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
} by {
	ld	hl,#0x0000
	ld	a,l
	ld	(#%1),hl
	; peephole z88dk-28a  Write 0 using 16bit store
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
} by {
	ld	hl,#0x0000
	ld	a,l
	ld	(#%1 + %2),hl
	; peephole z88dk-28b  Write 0 using 16bit store
} if notUsed('hl')

replace restart {
	ld	e,l
	ld	d,h
	ld	bc,#%1
	push	de
	push	bc
} by {
	push	hl
	ld	bc,#%1
	push	bc
	; peephole z88dk-29  Eliminate unnecessary load of hl into de
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	push	hl
	ld	hl,#%2
	push	hl
	push	de
	push	bc
} by {
	ld	bc,#%1
	push	bc
	ld	bc,#%2
	push	bc
	push	de
	push	hl
	; peephole z88dk-30
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	hl,#%1 + 2
	ld	c, (hl)
	inc	hl
	ld	b, (hl)
	push	bc
} by {
	ld	hl,(#%1 + 2)
	push	hl
	ld	hl,#%1 + 3
	; peephole z88dk-32
} if notUsed('bc')

replace restart {
	ld	(#%1),hl
	ld	de,#%2
	ld	hl,(#%1)
} by {
	ld	(#%1),hl
	ld	de,#%2
	; peephole z88dk-33
}
// if notVolatile

replace restart {
	ld	hl,#%1
	ld	(hl),a
	ld	d,(hl)
	ld	a,(hl)
} by {
	ld	(#%1),a
	ld	d,a
	ld	hl,#%1
	; peephole z88dk-34
} 
// if notVolatile

replace restart {
	ld	a,l
	ld	(#%1 + %2),a
	pop	af
} by {
	pop	af
	ld	a,l
	ld	(#%1 + %2),a
	; peephole z88dk-35
} if notUsed('a')

replace restart {
	ld	(#%1 + %2),a
	ld	iy,#%1
	ld	l,%2 (iy)
	ld	a,(#%1 + %2)
} by {
	ld	(#%1 + %2),a
	ld	l,a
	; peephole z88dk-36
} if notUsed('iy')
// if notVolatile

replace restart {
	ld	a,l
	ld	(#%1 + %2),a
	ld	l,a
} by {
	ld	a,l
	ld	(#%1 + %2),a
	; peephole z88dk-37
}

replace restart {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ld	iy,#%1
	ld	l,0 (iy)
	ld	iy,#%1
	ld	h,1 (iy)
	ld	iy,#%1
	ld	e,2 (iy)
	ld	iy,#%1
	ld	d,3 (iy)
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	; peephole z88dk-38
} if notUsed('iy')
// if notVolatile

replace restart {
	ld	iy,#%1
	ld	l,0 (iy)
	ld	iy,#%1
	ld	h,1 (iy)
	ld	iy,#%1
	ld	e,2 (iy)
	ld	iy,#%1
	ld	d,3 (iy)
} by {
	ld	hl,(#%1)
	ld	de,(#%1 + 2)
        ; peephole z88dk-39
} if notUsed('iy')

replace restart {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ld	de,#%2
	ld	hl,(%1 + 2)
	push	hl
	ld	hl,(%1)
	push	hl
	push	de
} by {
	ld	(#%1),hl
	ld	(#%1 + 2),de
	push	de
	push	hl
	ld	de,#%2
	push	de
	; peephole z88dk-40
}

replace restart {
	ld	c, l
	ld	b, h
	ld	hl,#%1
	add	hl,sp
	ld	sp,hl
	ld	(#%2),bc
} by {
	ld	c,l
	ld	b,h
	ld	(#%2),hl
	ld	hl,#%1
	add	hl,sp
	ld	sp,hl
	; peephole z88dk-41
} 

replace restart {
	call	%1
	ld	iy,#%2
	add	iy,sp
	ld	sp,iy
	ld	(%3),hl
} by {
	call	%1
	ld	(%3),hl
	ld	hl,#%2
	add	hl,sp
	ld	sp,hl
	; peephole z88dk-42
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	iy,#0
	add	iy,sp
	ld	3 (iy),d
	ld	2 (iy),e
	ld	1 (iy),h
	ld	0 (iy),l
	pop	hl
	pop	de
} by {
	; peephole z88dk-43
} if notUsed('iy')

replace restart {
	ld	iy,(%1)
	ld	de,(%2)
	add	iy, de
	ld	hl,#%3
	push	hl
	ld	hl,#%4
	push	hl
	ld	hl,#%5
	push	hl
	push	iy
} by {
	ld	hl,(%1)
	ld	de,(%2)
	add	hl,de
	ex	de,hl
	ld	hl,#%3
	push	hl
	ld	hl,#%4
	push	hl
	ld	hl,#%5
	push	hl
	push	de
	; peephole z88dk-44
} if notUsed('iy'), notUsed('de')

replace restart {
	ld	iy,#%1
	push	iy
	pop	de
} by {
	ld	de,#%1
	; peephole z88dk-45
} if notUsed('iy')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	e,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ex	de,hl
	ld	a,d
	ld	hl,#%2 + 1
	; peephole z88dk-46
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-47a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-47b
} if notUsed('bc')

replace restart {
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
	inc	hl
	xor	a, a
} by {
	xor	a, a
	ld	(hl), a
	inc	hl
	ld	(hl), a
	inc	hl
	; peephole z88dk-48
}

replace restart {
	ld	%1 (ix),d
	ld	%2 (ix),e
	ld	%3 (ix),h
	ld	%4 (ix), l
	ld	e, l
	ld	d,%3 (ix)
	ld	c,%2 (ix)
	ld	b,%1 (ix)
	bit	7, %1 (ix)
} by {
	ld	%1 (ix),d
	ld	%2 (ix),e
	ld	%3 (ix),h
	ld	%4 (ix),l
	ld	c,e
	ld	b,d
	ld	e,l
	ld	d,h
	bit	7,b
	; peephole z88dk-49
} 
// if notVolatile

replace restart {
	ld	%1 (ix),d
	ld	%2 (ix),e
	ld	%3 (ix),b
	ld	a,c
	and	a, #%4
	ld	%5 (ix),a
	ld	a,#%6
	cp	a, %1 (ix)
	ld	a,#%7
	sbc	a, %2 (ix)
	ld	a,#%8
	sbc	a, %3 (ix)
} by {
	ld	%1 (ix),d
	ld	%2 (ix),e
	ld	%3 (ix),b
	ld	a,c
	and	a, #%4
	ld	%5 (ix),a
	ld	a,#%6
	cp	a, d
	ld	a,#%7
	sbc	a, e
	ld	a,#%8
	sbc	a, b
	; peephole z88dk-51
}
// if notVolatile

replace restart {
	ld	l, %5 (ix)
	ld	h, %6 (ix)
	ld	de, #%7
	add	hl, de
	ld	a,(hl)
	ld	%1 (ix),a
	inc	hl
	ld	a,(hl)
	ld	%2 (ix),a
	inc	hl
	ld	a,(hl)
	ld	%3 (ix),a
	inc	hl
	ld	a,(hl)
	ld	%4 (ix),a
} by {
	push	ix
	pop	hl
	ld	de,#%1
	add	hl,de
	ex	de,hl
	ld	l, %5 (ix)
	ld	h, %6 (ix)
	ld	bc,#%7
	add	hl,bc
	ld	bc,#0x0004
	ldir
	dec	hl
	ld	a,(hl)
	; peephole z88dk-52  Warning may lead to incorrect code
} if notUsed('bc'), notUsed('de')

replace restart {
	ld	b,l
	ld	c,h
	ld	a,%1 (ix)
	add	a, b
	ld	%1 (ix),a
	ld	a,%2 (ix)
	adc	a, c
	ld	%2 (ix),a
	ld	a,%3 (ix)
	adc	a, e
	ld	%3 (ix),a
	ld	a,%4 (ix)
	adc	a, d
	ld	%4 (ix),a
} by {
	ld	c,%1 (ix)
	ld	b,%2 (ix)
	add	hl,bc
	ld	%1 (ix),l
	ld	%2 (ix),h
	ld	l,%3 (ix)
	ld	h,%4 (ix)
	adc	hl,de
	ld	%3 (ix),l
	ld	%4 (ix),h
	ld	a,h
	; peephole z88dk-53
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	%1 (ix),%3
	ld	%2 (ix),%4
	ld	%3,%1 (ix)
	ld	%4,%2 (ix)
} by {
	ld	%1 (ix),%3
	ld	%2 (ix),%4
	; peephole z88dk-55
}
// if notVolatile

replace restart {
	ld	%5 (ix), l
	ld	%6 (ix), h
	ld	%7 (ix),e
	ld	%8 (ix),d
	bit	%2, %3
	jp	%4,%1
	ld	h,%5 (ix)
	ld	l,%6 (ix)
	ld	d,%7 (ix)
	ld	e,%8 (ix)
} by {
	ld	%5 (ix),l
	ld	%6 (ix),h
	ld	%7 (ix),e
	ld	%8 (ix),d
	bit	%2, %3
	jp	%4,%1
	ld	a,h
	ld	h,l
	ld	l,a
	ld	a,d
	ld	d,e
	ld	e,a
	; peephole z88dk-56
} 

replace restart {
	ld	b,l
	ld	c,h
	pop	de
	ld	a,c
	or	a,b
	jp	%2,%1
} by {
	ld	b,l
	ld	c,h
	pop	de
	ld	a,h
	or	a,l
	jp	%2,%1
	; peephole z88dk-57
}

replace restart {
	ld	%1 (ix),h
	ld	%2 (ix),l
	pop	de
	pop	bc
	ld	a,%1 (ix)
	or	a,%2 (ix)
	jp	%4,%3
} by {
	ld	%1 (ix),h
	ld	%2 (ix),l
	pop	de
	pop	bc
	ld	a,h
	or	a,l
	jp	%4,%3
	; peephole z88dk-59
}
// if notVolatile

replace restart {
	ld	%1,%3 (ix)
	ld	%2,%3 (ix)
} by {
	ld	%1,%3 (ix)
	ld	%2,%1
	; peephole z88dk-61
}
// if notVolatile

replace restart {
	ld	d,a
	ld	a,c
	or	a, b
	or	a, e
	or	a, d
} by {
	ld	d,a
	or	a, c
	or	a, b
	or	a, e
	; peephole z88dk-64
}

replace restart {
	ld	b,l
	ld	c,h
	ld	%1 (ix),b
	ld	%2 (ix),c
	ld	%3 (ix),e
	ld	%4 (ix),d
} by {
	ld	b,l
	ld	c,h
	ld	%1 (ix),l
	ld	%2 (ix),h
	ld	%3 (ix),e
	ld	%4 (ix),d
	; peephole z88dk-66
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	dec	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	push	bc
	push	de
} by {
	ld	c,l
	ld	b,h
	push	hl
	ld	hl,(#%1)
	push	hl
	ld	e,l
	ld	d,h
	ld	hl,#%1 + 1
	; peephole z88dk-67
} 

replace restart {
	ld	%4 (ix),l
	ld	%3 (ix),h
	ld	%2 (ix),e
	ld	%1 (ix),d
	ld	l,%2 (ix)
	ld	h,%1 (ix)
	push	hl
	ld	l,%4 (ix)
	ld	h,%3 (ix)
	push	hl
} by {
	ld	%4 (ix),l
	ld	%3 (ix),h
	ld	%2 (ix),e
	ld	%1 (ix),d
	push	de
	push	hl
	; peephole z88dk-68
} 
// if notVolatile

replace restart {
	ld	%4 (ix),c
	ld	%3 (ix),b
	ld	%2 (ix),e
	ld	%1 (ix),d
	push	af
	ld	a,%4 (ix)
	ld	%8 (ix),a
	ld	a,%3 (ix)
	ld	%7 (ix),a
	ld	a,%2 (ix)
	ld	%6 (ix),a
	ld	a,%1 (ix)
	ld	%5 (ix),a
	pop	af
} by {
	ld	%4 (ix),c
	ld	%3 (ix),b
	ld	%2 (ix),e
	ld	%1 (ix),d
	ld	%8 (ix),c
	ld	%7 (ix),b
	ld	%6 (ix),e
	ld	%5 (ix),d
	; peephole z88dk-69
}
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	pop	de
	ld	l, b
	ld	h, c
} by {
	ld	b,l
	ld	c,h
	pop	de
	; peephole z88dk-71
}

replace restart {
	ld	de, (#%1 + %2)
	ld	hl, (#%3 + %4)
	ld	a,e
	sub	a, l
	ld	e,a
	ld	a,d
	sbc	a, h
	ld	d,a
} by {
	ld	hl, (#%1 + %2)
	ld	de, (#%3 + %4)
	xor	a,a
	sbc	hl,de
	ex	de,hl
	ld	a,d
	; peephole z88dk-72
}

replace restart {
	push	%1
	pop	%1
} by {
	; peephole z88dk-73 Remove push %1 / pop %1 pair
}

replace restart {
	ld	%1,%2 (%3)
	ld	%2 (%3),%1
} by {
	ld	%1,%2 (%3)
	; peephole z88dk-75a
}
// if notVolatile

replace restart {
	ld	%1 (%6),%3
	ld	%4,%2 (%6)
	ld	%5,%1 (%6)
} by {
	ld	%4,%2 (%6)
	ld	%1 (%6),%3
	ld	%5,%3
	; peephole z88dk-75b
} if notSame(%1 %2), notSame(%3 %4)
// notVolatile

replace restart {
	ld	a,%2 (%4)
	ld	%1,%3 (%4)
} by {
	ld	%1,%3 (%4)
	ld	a,%2 (%4)
	; peephole z88dk-75c
} if notSame(%1 'a')

replace restart {
	ld	iy,#%1
	ld	0 (iy),h
	ld	iy,#%1
	ld	1 (iy),l
	ld	iy,#%1
	sra	1 (iy)
	ld	iy,#%1
	rr	0 (iy)
} by {
	ld	a,l
	ld	l,h
	ld	h,a
	sra	h
	rr	l
	ld	(#%1),hl
	; peephole z88dk-76
} if notUsed('iy'), notUsed('a'), notUsed('hl')

replace restart {
	ld	iy,#%1
	ld	0 (iy),h
	ld	iy,#%1
	ld	1 (iy),l
} by {
	ld	a,l
	ld	l,h
	ld	h,a
	ld	(#%1),hl
	; peephole z88dk-77
} if notUsed('iy'), notUsed('a'), notUsed('hl')

replace restart {
	ld	a,(#%1 + 1)
	ld	hl,#%1 + 0
	or	a,(hl)
} by {
	ld	hl,(#%1)
	ld	a,h
	or	a,l
	; peephole z88dk-78
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	dec	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	sla	e
	rl	d
} by {
	ld	hl,(#%1 + %2 - 1)
	add	hl,hl
	ex	de,hl
	ld	hl,#%1 + %2
	; peephole z88dk-79
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	jp	NZ,%3
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sub	a, (hl)
	jp	Z,%4
%3:
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	jp	Z,%4
%3:
	; peephole z88dk-80  Warning may lead to incorrect code
} if notUsed('a'), notUsed('de'), notUsed('hl')

replace restart {
	jp	%1
%1:
} by {
%1:
	; peephole z88dk-81
}
// if decrement label count

replace restart {
	ld	a,(#%1 + 0)
	ld	iy,#%2
	sub	a, 0 (iy)
	jp	NZ,%3
	ld	a,(#%1 + 1)
	ld	iy,#%2
	sub	a, 1 (iy)
	jp	Z,%4
%3:
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	jp	Z,%4
%3:
	; peephole z88dk-82  Warning may lead to incorrect code
} if notUsed('a'), notUsed('de'), notUsed('hl'), notUsed('iy')

replace restart {
	ld	hl,#%1 + %2
	dec	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	de,(#%1 + %2 - 1)
	ld	hl,#%1 + %2
	; peephole z88dk-83
}

replace restart {
	ex	de,hl
	sla	e
	rl	d
} by {
	add	hl,hl
	ex	de,hl
	; peephole z88dk-84
}

replace restart {
	ld	b,l
	ld	c,h
	bit	7, c
	jp	Z,%1
	ld	l, b
	ld	h, c
} by {
	ld	b,l
	ld	c,h
	bit	7, c
	jp	Z,%1
	; peephole z88dk-86
}

replace restart {
	ex	de,hl
	ld	((%1 + %2)), de
} by {
	ld	((%1 + %2)),hl
	ex	de,hl
	; peephole z88dk-87
}

replace restart {
	ex	de,hl
	ld	((%1 - %2)), de
} by {
	ld	((%1 - %2)),hl
	ex	de,hl
	; peephole z88dk-88
}

replace restart {
	add	hl,%2
	ld	c,h
	bit	7, c
	jp	Z,%1
} by {
	add	hl,%2
	ld	c,h
	jp	P,%1
	; peephole z88dk-89a
} 

replace restart {
	add	hl, %1
	ld	b,l
	ld	c,h
	bit	7, h
	jp	Z,%2
} by {
	add	hl, %1
	ld	b,l
	ld	c,h
	jp	P,%2
	; peephole z88dk-89b
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	%3 (ix),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	%4 (ix),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	%3 (ix),l
	ld	%4 (ix),h
	ld	a,h
	; peephole z88dk-91a
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(#%2 + 0)
	sub	a, (hl)
	ld	%3 (ix),a
	ld	a,(#%2 + 1)
	inc	hl
	sbc	a, (hl)
	ld	%4 (ix),a
} by {
	ld	hl,(#%2)
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	%3 (ix),l
	ld	%4 (ix),h
	ld	a,h
	; peephole z88dk-91b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	e,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ex	de,hl
	ld	a,d
	; peephole z88dk-92a
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(#%2 + 0)
	sub	a, (hl)
	ld	e,a
	ld	a,(#%2 + 1)
	inc	hl
	sbc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%2)
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ex	de,hl
	ld	a,d
	; peephole z88dk-92b
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	jp	NZ,%3
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sub	a, (hl)
	jp	NZ,%3
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	jp	NZ,%3
	; peephole z88dk-93a  Warning may lead to incorrect code
} if notUsed('a'), notUsed('bc'), notUsed('hl')

replace restart {
	ld	a,(#%1 + 0)
	ld	iy,#%2
	sub	a, 0 (iy)
	jp	NZ,%5
	ld	a,(#%1 + 1)
	ld	iy,#%2
	sub	a, 1 (iy)
	jp	NZ,%5
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	jp	NZ,%5
	; peephole z88dk-93b  Warning may lead to incorrect code
} if notUsed('a'), notUsed('bc'), notUsed('hl')

replace restart {
	ld	bc, (#(%1 + %2) + %3)
	ld	hl, (#(%4 + %5) + %6)
	ld	a,c
	sub	a, l
	ld	l,a
	ld	a,b
	sbc	a, h
	ld	h,a
} by {
	ld	hl, (#(%1 + %2) + %3)
	ld	bc, (#(%4 + %5) + %6)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	; peephole z88dk-94a
} if notUsed('bc')

replace restart {
	ld	de,(#%1 + %2 - %2)
} by {
	ld	de,(#%1)
	; peephole z88dk-95a
}

replace restart {
	ld	hl,(#%1 + %2 - %2)
} by {
	ld	hl,(#%1)
	; peephole z88dk-95b
}

replace restart {
	ld	bc,(#%1 + %2 - %2)
} by {
	ld	bc,(#%1)
	; peephole z88dk-95c
}

replace restart {
	ld	de,(#%1)
	ld	a,(de)
} by {
	ld	hl,(#%1)
	ld	a,(hl)
	; peephole z88dk-96a
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	bc,(#%1)
	ld	a,(bc)
} by {
	ld	hl,(#%1)
	ld	a,(hl)
	; peephole z88dk-96b
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	dec	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	de,(#%1 + %2 - 1)
	ld	hl,#%1 + %2
	; peephole z88dk-97
} 

replace restart {
	ld	de, (#%1 + %2)
	ld	((%3 + %4)), de
} by {
	ld	hl, (#%1 + %2)
	ld	((%3 + %4)), hl
        ; peephole z88dk-98a
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	bc, (#%1 + %2)
	ld	((%3 + %4)), bc
} by {
	ld	hl, (#%1 + %2)
	ld	((%3 + %4)), hl
        ; peephole z88dk-98b
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	ld	(#%1),de
	ld	hl,#%1 + 1
	; peephole z88dk-99
} 

replace restart {
	ld	d,l
	ld	e,h
	pop	hl
	push	hl
	ld	(hl),d
	inc	hl
	ld	(hl),e
	ld	hl,#%1
	ld	(hl),d
	inc	hl
	ld	(hl),e
} by {
	ld	e,l
	ld	d,h
	pop	hl
	push	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	(#%1),de
	; peephole z88dk-100
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	a,l
	ld	d,h
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	(hl),d
} by {
	ld	a,l
	ld	d,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-101
} 

replace restart {
	ld	iy,#%1
	ld	l,%2 (iy)
	ld	h,#0x00
} by {
	ld	hl,(#%1 + %2)
	ld	h,#0x00
	; peephole z88dk-102
} if notUsed('iy')


replace restart {
	ld	hl,#%1 + %2
	ld	e, (hl)
	ld	d,#0x00
} by {
	ld	de,(#%1 + %2)
	ld	d,#0x00
	; peephole z88dk-103
} if notUsed('hl')

replace restart {
	ld	de,(%1)
	ld	l, e
	ld	h, d
} by {
	ld	hl,(%1)
	ld	e,l
	ld	d,h
	; peephole z88dk-104
} 

replace restart {
	ld	iy,#%1
	inc	0 (iy)
	ld	a,(#%1 + 0)
} by {
	ld	a,(#%1)
	inc	a
	ld	(#%1),a
	; peephole z88dk-105
} if notUsed('iy')

replace restart {
	ld	hl,#%1
	ld	d,(hl)
	ld	e,#0x00
	ld	l, d
	ld	h, e
} by {
	ld	hl,(#%1)
	ld	h,#0x00
	ld	d,l
	ld	e,h
	; peephole z88dk-106
} 

replace restart {
	ex	de,hl
	ld	hl,#%1
	add	hl,de
} by {
	ld	de,#%1
	add	hl,de
	; peephole z88dk-107
} if notUsed('de')

replace restart {
	xor	a, a
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	(hl),a
	inc	hl
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x0000
	ld	a,l
	ld	(#%1),hl
	ld	(#%1 + 2),hl
	ld	hl,#%1 + 3
	; peephole z88dk-108
} 

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	; peephole z88dk-109
} if notUsed('hl')

replace restart {
	ex	(sp), hl
	pop	hl
	push	hl
} by {
	pop	af
	push	hl
	; peephole z88dk-111
} if notUsed('a')

replace restart {
	ld	a,l
	ld	d,h
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	(hl),d
	ld	a,(hl)
	dec	hl
	or	a,(hl)
} by {
	ld	(#%1),hl
	ld	a,h
	or	a,l
	ld	d,h
	ld	hl,#%1
	; peephole z88dk-113
}
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	a,(hl)
	add	a, b
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a, c
	ld	d,a
} by {
	ld	de,(#%1)
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-114
} if notUsed('bc')

replace restart {
	ld	b,l
	ld	c,h
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
} by {
	ld	b,l
	ld	c,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-115
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,#0x%2
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%3
	ld	(hl),a
	ld	a,(hl)
	dec	hl
	or	a,(hl)
} by {
	ld	hl,(#%1)
	ld	de,#0x%3%2
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	or	a,l
	ld	hl,#%1
	; peephole z88dk-116a
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,#0x%2
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%3
	ld	(hl),a
	ld	a,(hl)
	dec	hl
	or	a,(hl)
} by {
	ld	hl,(#%1)
	ld	bc,#0x%3%2
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	or	a,l
	ld	hl,#%1
	; peephole z88dk-116b
} if notUsed('bc')

replace restart {
	ld	a,e
	add	a,#0x%2
	ld	hl,#%1
	ld	(hl),a
	ld	a,d
	adc	a,#0x%3
	inc	hl
	ld	(hl),a
	dec	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	hl,#0x%3%2
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-117
}
// if notVolatile

replace restart {
	ex	de,hl
	ld	bc,#%1
	push	bc
	push	de
} by {
	ld	bc,#%1
	push	bc
	push	hl
	; peephole z88dk-118
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	dec	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	sla	c
	rl	b
} by {
	ld	hl,(#%1 + %2 - 1)
	add	hl,hl
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %2
	; peephole z88dk-119
}

replace restart {
	ld	hl, (#(%1 + %2) + %3)
	ld	l, d
	ld	h, e
} by {
	ld	l, d
	ld	h, e
	; peephole z88dk-120
}
// if notVolatile

replace restart {
	ld	d,l
	ld	e,h
	ld	bc, (#(%1 + %2) + %3)
	ld	l, d
	ld	h, e
} by {
	ld	d,l
	ld	e,h
	ld	bc, (#(%1 + %2) + %3)
	; peephole z88dk-121
}

replace restart {
	ld	de, #%1 + %2
	ld	a,(de)
	ld	hl,#%3
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ld	hl,(#%1 + %2)
	ld	(#%3),hl
	ld	hl,(#%1 + %2 + 2)
	ld	(#%3 + 2),hl
	ld	de,#%1 + %2 + 3
	ld	hl,#%3 + 3
	; peephole z88dk-122
}

replace restart {
	ld	hl, (#%1 + %2)
	ld	hl,#%3
} by {
	ld	hl,#%3
	; peephole z88dk-123
}
// if notVolatile

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, e
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a, d
	ld	d,a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-124
}

replace restart {
	ex	de,hl
	ld	hl,#%1
	push	de
	push	hl
} by {
	push	hl
	ld	hl,#%1
	push	hl
	; peephole z88dk-125
} if notUsed('de')

replace restart {
	ld	de, (#(%1 + %2) + %3)
	ld	bc, (#(%4 + %5) + %6)
	ld	(#%7),de
} by {
	ld	hl, (#(%1 + %2) + %3)
	ld	bc, (#(%4 + %5) + %6)
	ld	(#%7),hl
	; peephole z88dk-126
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	iy,#%1
	inc	0 (iy)
	jp	%2,%3
	ld	iy,#%1
	inc	1 (iy)
} by {
	ld	iy,#%1
	inc	0 (iy)
	jp	%2,%3
	inc	1 (iy)
	; peephole z88dk-127
}

replace restart {
	ld	iy,#%1
	inc	0 (iy)
	jp	NZ,%2
	inc	1 (iy)
%2:
} by {
	ld	hl,#%1
	inc	(hl)
	jp	NZ,%2
	inc	hl
	inc	(hl)
%2:
	; peephole z88dk-128
} if notUsed('iy'), notUsed('hl')

replace restart {
	ld	a,(#%1 + 0)
	sub	a, #0x%2
	ld	iy,#%1
	ld	a,1 (iy)
	sbc	a, #0x%3
	jp	%4,%5
} by {
	ld	hl,(#%1)
	ld	de,#$0x%3%2
	xor	a,a
	sbc	hl,de
	ld	a,h
	jp	%4,%5
	; peephole z88dk-129a  Warning may lead to incorrect code
} if notUsed('de'), notUsed('hl'), notUsed('iy')

replace restart {
	ld	a,(#%1 + 0)
	sub	a, #0x%2
	ld	iy,#%1
	ld	a,1 (iy)
	sbc	a, #0x%3
	jp	%4,%5
} by {
	ld	hl,(#%1)
	ld	bc,#$0x%3%2
	xor	a,a
	sbc	hl,bc
	ld	a,h
	jp	%4,%5
	; peephole z88dk-129b  Warning may lead to incorrect code
} if notUsed('bc'), notUsed('hl'), notUsed('iy')

replace restart {
	xor	a, a
	ld	(#%1 + 0),a
	ld	(#%1 + 1),a
	ld	(#%1 + 2),a
	ld	(#%1 + 3),a
} by {
	ld	hl,#0x0000
	ld	a,l
	ld	(#%1),hl
	ld	(#%1 + 2),hl
	; peephole z88dk-130
} if notUsed('hl')

replace restart {
	ld	de,(%1)
	sla	e
	rl	d
} by {
	ld	hl,(%1)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-131
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,e
	add	a,#0x%2
	ld	(hl),a
	ld	a,d
	adc	a,#0x%3
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x%3%2
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-132
}

replace restart {
	ld	hl,#%1 + 0
	ld	c, (hl)
	ld	hl,#%1 + 1
	ld	b, (hl)
} by {
	ld	bc,(#%1)
	ld	hl,#%1 + 1
	; peephole z88dk-133a
}

replace restart {
	ld	hl,#%1 + 2
	ld	c, (hl)
	ld	hl,#%1 + 3
	ld	b, (hl)
} by {
	ld	bc,(#%1 + 2)
	ld	hl,#%1 + 3
	; peephole z88dk-133b
}

replace restart {
	ld	hl,#%1 + 0
	ld	e, (hl)
	ld	hl,#%1 + 1
	ld	d, (hl)
} by {
	ld	de,(#%1)
	ld	hl,#%1 + 1
	; peephole z88dk-133c
}

replace restart {
	ld	hl,#%1 + 2
	ld	e, (hl)
	ld	hl,#%1 + 3
	ld	d, (hl)
} by {
	ld	de,(#%1 + 2)
	ld	hl,#%1 + 3
	; peephole z88dk-133d
}

replace restart {
	ld	bc,(#%1)
	ld	hl,#%2
	ld	de,#%3
	push	hl
	push	bc
} by {
	ld	hl,(#%1)
	ld	bc,#%2
	ld	de,#%3
	push	bc
	push	hl
	; peephole z88dk-134
} if notUsed('hl'), notUsed('bc')

replace restart {
	ld	(#%1),hl
	ld	hl,(#%1)
} by {
	ld	(#%1),hl
	; peephole z88dk-135 Remove redundant load
} if notVolatile(%1)

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	d,a
	ld	a,#>(%1)
	adc	a, h
	ld	e,a
	ld	bc, (#(%2 + %3) + %4)
	ld	l, d
	ld	h, e
} by {
	ld	de,#%1
	add	hl,de
	ld	bc, (#(%2 + %3) + %4)
	ld	d,l
	ld	e,h
	; peephole z88dk-136
}

replace restart {
	ld	hl, #%1 + 0
	ld	a,(hl)
	ld	iy,#%2
	ld	0 (iy),a
	inc	hl
	ld	a,(hl)
	ld	iy,#%2
	ld	1 (iy),a
	inc	hl
	ld	a,(hl)
	ld	iy,#%2
	ld	2 (iy),a
	inc	hl
	ld	a,(hl)
	ld	(#%2 + 3),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	a,h
	ld	hl,#%1 + 3
	; peephole z88dk-137
} if notUsed('iy')

replace restart {
	ld	hl,#%1 + 0
	ld	e, (hl)
	ld	hl,#%1 + 1
	ld	d, (hl)
} by {
	ld	de,(#%1)
	ld	hl,#%1 + 1
	; peephole z88dk-139
}

replace restart {
	ld	iy,#%1
	ld	0 (iy),l
	ld	iy,#%1
	ld	1 (iy),h
} by {
	ld	(#%1),hl
	; peephole z88dk-140
} if notUsed('iy')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,#0x%2
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%3
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,#0x%3%2
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	; peephole z88dk-141a
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,#0x%2
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%3
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,#0x%3%2
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	; peephole z88dk-141b
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	bc, (#(%1 + %2) + %3)
} by {
	; peephole z88dk-142a
} if notUsed('bc')

replace restart {
	ld	de, (#(%1 + %2) + %3)
} by {
	; peephole z88dk-142b
} if notUsed('de')

replace restart {
	ld	hl, (#(%1 + %2) + %3)
} by {
	; peephole z88dk-142c
} if notUsed('hl')

replace restart {
;	---------------------------------
; Function %1
; ---------------------------------
_%1::
	jp	%2
} by {
;	---------------------------------
; Function %1
; ---------------------------------
_%1	=	%2
	; peephole z88dk-143
}

replace restart {
	ld	a,l
	add	a,#0xFF
	ld	%1 (ix),a
	ld	a,h
	adc	a,#0xFF
	ld	%2 (ix),a
} by {
	dec	hl
	ld	%1 (ix),l	
	ld	%2 (ix),h
	ld	a,h
	inc	hl
	; peephole z88dk-144
}

replace restart {
	ex	de,hl
	pop	bc
	ld	l, e
	ld	h, d
} by {
	pop	bc
	ld	e,l
	ld	d,h
	; peephole z88dk-145
}

replace restart {
	ld	d,l
	ld	e,h
	ld	a,%1 (ix)
	add	a, d
	ld	d,a
	ld	a,%2 (ix)
	adc	a, e
	ld	%3 (ix), d
	ld	%4 (ix), a
} by {
	ld	e,%1 (ix)
	ld	d,%2 (ix)
	add	hl,de
	ld	%3 (ix), l
	ld	%4 (ix), h
	ld	a,h
	; peephole z88dk-146
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	d,l
	ld	b,h
	ld	a,%1 (ix)
	add	a, d
	ld	e,a
	ld	a,%2 (ix)
	adc	a, b
	ld	d,a
} by {
	ex	de,hl
	ld	l,%1 (ix)
	ld	h,%2 (ix)
	add	hl,de
	ex	de,hl
	ld	a,d
	ld	b,h
	; peephole z88dk-147
}

replace restart {
	pop	de
	pop	%1
	ex	de,hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	pop	hl
	pop	%1
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	; peephole z88dk-148
}

replace restart {
	ld	c,l
	ld	b,h
	pop	de
	push	bc
} by {
	pop	de
	push	hl
	; peephole z88dk-149
} if notUsed('bc')

replace restart {
	ld	d,l
	ld	e,h
	pop	bc
	ld	%1 (ix),d
	ld	%2 (ix),e
} by {
	pop	bc
	ld	%1 (ix),l
	ld	%2 (ix),h
	; peephole z88dk-150
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	d,(hl)
	inc	hl
	ld	e,(hl)
	ld	l, d
	ld	h, e
} by {
	ld	hl,(#%1)
	ld	d,l
	ld	e,h
	; peephole z88dk-152
}

replace restart {
	pop	bc
	ld	l, c
	ld	h, b
} by {
	pop	hl
	; peephole z88dk-153
} if notUsed('bc')

replace restart {
	ld	de,(#%1)
	ld	d,#%2
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	ld	h,#%2
	ld	e, l
	ld	d, h
	; peephole z88dk-154a
}

replace restart {
	ld	bc,(%1)
	ld	b,#%2
	ld	l, c
	ld	h, b
} by {
	ld	hl,(%1)
	ld	h,#%2
	ld	c, l
	ld	b, h
	; peephole z88dk-154b
}

replace restart {
	ld	%3,#%2
	push	%1
	ld	%3,#%2
	push	%1
	ld	%3,#%2
	push	%1
} by {
	ld	%3,#%2
	push	%1
	push	%1
	push	%1
	; peephole z88dk-155a
}

replace restart {
	ld	%3,#%2
	push	%1
	ld	%3,#%2
	push	%1
} by {
	ld	%3,#%2
	push	%1
	push	%1
	; peephole z88dk-155b
}

replace restart {
	ld	iy,#%1
	ld	%2 (iy),a
} by {
	ld	(#%1 + %2),a
	ld	iy,#%1
	; peephole z88dk-156a
}

replace restart {
	ld	iy,#%1
	ld	%2 (iy),#%3
} by {
	ld	a,#%3
	ld	(#%1 + %2),a
	ld	iy,#%1
	; peephole z88dk-156b
} if notUsed('a')

replace restart {
	ld	hl,#%1
	ld	e,(hl)
	ld	d,#%2
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	ld	h,#%2
	ld	e,l
	ld	d,h
	; peephole z88dk-157a
}

replace restart {
	ld	hl,#%1
	ld	c,(hl)
	ld	b,#%2
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	ld	h,#%2
	ld	c,l
	ld	b,h
	; peephole z88dk-157b
}

replace restart {
	ld	hl,#%1
	ld	c,(hl)
	ld	b,#%4
} by {
	ld	bc,(#%1)
	ld	b,#%4
	; peephole z88dk-158a
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	e,(hl)
	ld	d,#%4
} by {
	ld	de,(#%1)
	ld	d,#%4
	; peephole z88dk-158b
} if notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	ld	a,(#%1)
	ld	(bc),a
} by {
	ld	a,(#%1)
	ld	(hl),a
	ld	c,l
	ld	b,h
	; peephole z88dk-159a
}

replace restart {
	ld	e,l
	ld	d,h
	ld	a,(#%1)
	ld	(de),a
} by {
	ld	a,(#%1)
	ld	(hl),a
	; peephole z88dk-159b
} if notUsed('de')

replace restart {
	ex	de,hl
	ld	a,(#%1)
	ld	(de),a
} by {
	ld	a,(#%1)
	ld	(hl),a
	; peephole z88dk-159c
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	xor	a,a
	ld	(bc),a
} by {
	xor	a,a
	ld	(hl),a
	ld	c,l
	ld	b,h
	; peephole z88dk-159d
}

replace restart {
	ld	hl,#%1
	ld	b,(hl)
	inc	hl
	ld	c,(hl)
	ld	l, b
	ld	h, c
} by {
	ld	hl,(#%1)
	ld	b, l
	ld	c, h
	; peephole z88dk-160a
}

replace restart {
	ld	hl,#%1
	ld	d,(hl)
	inc	hl
	ld	e,(hl)
	ld	l, d
	ld	h, e
} by {
	ld	hl,(#%1)
	ld	d, l
	ld	e, h
	; peephole z88dk-160b
}

replace restart {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	sla	e
	rl	d
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-161a
} if notUsed('hl')

replace restart {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	sla	e
	rl	d
} by {
	ex	de,hl
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-161b
}

replace restart {
	ex	de,hl
	sla	e
	rl	d
} by {
	add	hl,hl
	ex	de,hl
	; peephole z88dk-161c
}

replace restart {
	ex	de,hl
	ld	hl,#%1
	add	hl,de
} by {
	ld	de,#%1
	add	hl,de
	; peephole z88dk-161d
} if notUsed('de')

replace restart {
	ld	%1,%2 + %3 - %3
} by {
	ld	%1,%2
	; peephole z88dk-162
}

replace restart {
	ld	hl,#%3
	ld	%1,(hl)
	inc	hl
	ld	%2,(hl)
	ld	l, %1
	ld	h, %2
} by {
	ld	hl,(#%3)
	ld	%1, l
	ld	%2, h
	; peephole z88dk-163
}

replace restart {
	ld	a,(hl)
	ld	(de),a
	inc	de
	inc	hl
} by {
	ldi
	; peephole z88dk-164a
} if notUsed('bc')

replace restart {
	ld	a,(hl)
	ld	(de),a
	inc	de
	inc	hl
} by {
	ldi
	inc	bc
	; peephole z88dk-164b
}

replace restart {
	ld	hl,#%1
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	inc	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
} by {
	ld	de,(#%1)
	ld	bc,(#%1 + 2)
	ld	hl,#%1 + 3
	; peephole z88dk-165a
}

replace restart {
	ld	hl,#%1
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	bc,(#%1)
	ld	de,(#%1 + 2)
	ld	hl,#%1 + 3
	; peephole z88dk-165b
}

replace restart {
	ld	hl,#%1
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
} by {
	ld	de,(#%1)
	ld	hl,#%1 + 1
	; peephole z88dk-166a
}

replace restart {
	ld	hl,#%1
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
} by {
	ld	bc,(#%1)
	ld	hl,#%1 + 1
	; peephole z88dk-166b
}

replace restart {
	ld	de,(#%1)
	dec	de
	ld	%2 (ix),e
	ld	%3 (ix),d
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	dec	hl
	ld	%2 (ix),l
	ld	%3 (ix),h
	ld	e,l
	ld	d,h
	; peephole z88dk-167a
}

replace restart {
	ld	de,(#%1)
	dec	de
	ld	%2 (ix),e
	ld	%2 (ix),d
} by {
	ld	hl,(#%1)
	dec	hl
	ld	%2 (ix),l
	ld	%3 (ix),h
	; peephole z88dk-167b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	ld	(#%1),de
	ld	hl,#%1 + 1
	; peephole z88dk-168a
}

replace restart {
	ld	hl,#%1
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	(#%1),bc
	ld	hl,#%1 + 1
	; peephole z88dk-168b
}

replace restart {
	ld	hl,#%1
	ld	b,(hl)
	inc	hl
	ld	c,(hl)
	sla	b
	rl	c
	ld	a,e
	add	a, b
	ld	e,a
	ld	a,d
	adc	a, c
	ld	d,a
} by {
	ld	hl,(#%1)
	add	hl,hl
	ld	b,l
	ld	c,h
	add	hl,de
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-169
}

replace restart {
	ex	de,hl
	ld	hl,#%1
	add	hl,de
	ex	de,hl
} by {
	ld	de,#%1
	add	hl,de
	ex	de,hl
	; peephole z88dk-170
} if notUsed('hl')

replace restart {
	dec	hl
	ld	%1,(hl)
	inc	hl
	ld	%2,(hl)
} by {
	ld	%2,(hl)
	dec	hl
	ld	%1,(hl)
	; peephole z88dk-171
} if notUsed('hl'), operandsNotRelated(%1 'hl'), operandsNotRelated(%2 'hl')

replace restart {
	sla	e
	rl	d
	sla	e
	rl	d
} by {
	ex	de,hl
	add	hl,hl
	add	hl,hl
	ex	de,hl
	; peephole z88dk-172
}

replace restart {
	ld	de,(#%1)
	%2	de
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	%2	hl
	ld	e, l
	ld	d, h
	; peephole z88dk-173a
}

replace restart {
	ld	bc,(#%1)
	%2	bc
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	%2	hl
	ld	c, l
	ld	b, h
	; peephole z88dk-173b
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	%3 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%4 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%5 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%6 (%2),a
} by {
	ld	hl,(#%1)
	ld	%3 (%2),l
	ld	%4 (%2),h
	ld	hl,(#%1 + 2)
	ld	%5 (%2),l
	ld	%6 (%2),h
	ld	a,h
	ld	hl,#%1 + 3
	; peephole z88dk-174a
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	%3 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%4 (%2),a
} by {
	ld	hl,(#%1)
	ld	%3 (%2),l
	ld	%4 (%2),h
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-174b
}

replace restart {
	ld	a, %3 (%2)
	ld	hl,#%1
	ld	(hl),a
	ld	a, %4 (%2)
	inc	hl
	ld	(hl),a
	ld	a, %5 (%2)
	inc	hl
	ld	(hl),a
	ld	a, %6 (%2)
	inc	hl
	ld	(hl),a
} by {
	ld	l,%3 (%2)
	ld	h,%4 (%2)
	ld	(#%1),hl
	ld	l,%5 (%2)
	ld	h,%6 (%2)
	ld	(#%1 + 2),hl
	ld	a,h
	ld	hl,#%1 + 3
	; peephole z88dk-175a
}

replace restart {
	ld	a, %3 (%2)
	ld	hl,#%1
	ld	(hl),a
	ld	a, %4 (%2)
	inc	hl
	ld	(hl),a
} by {
	ld	l,%3 (%2)
	ld	h,%4 (%2)
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-175b
}

replace restart {
	ld	hl,#%1 + %2
	ld	a,%3 (%4)
	inc	hl
	ld	(hl),a
	ld	a,%5 (%6)
	inc	hl
	ld	(hl),a
} by {
	ld	l,%3 (%4)
	ld	h,%5 (%6)
	ld	(#%1 + %2+1),hl
	ld	a,h
	ld	hl,#%1 + %2+2
	; peephole z88dk-175c
}

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	ld	%3 (%4),a
	inc	hl
	ld	a,(hl)
	ld	%5 (%6),a
} by {
	ld	hl,(#%1 + %2)
	ld	%3 (%4),l
	ld	%5 (%6),h
	ld	a,h
	ld	hl,#%1 + %2+1
	; peephole z88dk-175d
}

replace restart {
	ld	(#%1),%2
	ld	%2,(#%1)
} by {
	ld	(#%1),%2
	; peephole z88dk-176a
} if notVolatile(%1)

replace restart {
	ld	%1,(#%2)
	ld	(#%2),%1
} by {
	ld	%1,(#%2)
	; peephole z88dk-176b
} if notVolatile(%2)

replace restart {
	ld	c,l
	ld	b,h
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	push	hl
	push	bc
} by {
	ld	c,%1 (%3)
	ld	b,%2 (%3)
	push	bc
	push	hl
	; peephole z88dk-177a
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	e,l
	ld	d,h
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	push	hl
	push	de
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	push	de
	push	hl
	; peephole z88dk-177b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	e,l
	ld	d,h
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	push	hl
	push	de
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	ex	de,hl
	push	hl
	push	de
	; peephole z88dk-177c
} 

replace restart {
	ld	b,l
	ld	c,h
	pop	de
	ld	a,b
	sub	a, e
	ld	l,a
	ld	a,c
	sbc	a, d
	ld	h,a
} by {
	ld	b,l
	ld	c,h
	pop	de
	xor	a,a
	sbc	hl,de
	ld	a,h
	; peephole z88dk-178
}

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	; peephole z88dk-179a1
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	; peephole z88dk-179a2
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ex	de,hl
	; peephole z88dk-179b1
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	ex	de,hl
	; peephole z88dk-179b2
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	; peephole z88dk-179c1
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	a,h
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	a,h
	; peephole z88dk-179c2
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ex	de,hl
	; peephole z88dk-179d1
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	a,h
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	a,h
	ex	de,hl
	; peephole z88dk-179d2
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	; peephole z88dk-179e1
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	ld	a,h
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	ld	a,h
	; peephole z88dk-179e2
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	ex	de,hl
	; peephole z88dk-179f1
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	ld	a,h
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#%5)
	ld	(#%6),hl
	ld	hl,(#%7)
	ld	(#%8),hl
	ld	a,h
	ex	de,hl
	; peephole z88dk-179f2
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + %3)
	ld	(#%2 + %4),hl
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + %3)
	ld	(#%2 + %4),hl
	; peephole z88dk-179g1
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + %3)
	ld	(#%2 + %4),hl
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + %3)
	ld	(#%2 + %4),hl
	ex	de,hl
	; peephole z88dk-179g2
} if notUsed('de')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#_%3 + 2)
	ld	(#%4 + 2),hl
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#_%3 + 2)
	ld	(#%4 + 2),hl
	; peephole z88dk-179h1
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#_%3 + 2)
	ld	(#%4 + 2),hl
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	hl,(#%3)
	ld	(#%4),hl
	ld	hl,(#_%3 + 2)
	ld	(#%4 + 2),hl
	ex	de,hl
	; peephole z88dk-179h1
} if notUsed('de')

replace restart {
	ld	%1,#%2
	ld	%3,%4
	ld	%5,%6
	ld	%1,#%2
} by {
	ld	%1,#%2
	ld	%3,%4
	ld	%5,%6
	; peephole z88dk-180  Removed load of #%2 into %1 since it's still there.
} if notVolatile(%1), operandsNotRelated(%3 %1), operandsNotRelated(%5 %1)

replace restart {
	ld	%1 (%5),d
	ld	%2 (%5),e
	ld	%3 (%5),h
	ld	%4 (%5),l
	ld	l,%2 (%5)
	ld	h,%1 (%5)
	push	hl
	ld	l,%4 (%5)
	ld	h,%3 (%5)
	push	hl
} by {
	ld	%1 (%5),d
	ld	%2 (%5),e
	ld	%3 (%5),h
	ld	%4 (%5),l
	push	de
	push	hl
	; peephole z88dk-181
}
// if notVolatile

replace restart {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	inc	hl
	inc	hl
	ld	(hl),%4
	ld	l,%1 (%3)
	ld	h,%2 (%3)
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	inc	hl
	inc	hl
	ld	(hl),%4
	dec	hl
	dec	hl
	; peephole z88dk-182f
}
// if notVolatile()

replace restart {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	inc	hl
	ld	(hl),%4
	ld	l,%1 (%3)
	ld	h,%2 (%3)
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	inc	hl
	ld	(hl),%4
	dec	hl
	; peephole z88dk-182d
}
// if notVolatile()

replace restart {
	ld	%1 (%3),l
	ld	%2 (%3),h
	ld	(hl),%4
	ld	l,%1 (%3)
	ld	h,%2 (%3)
} by {
	ld	%1 (%3),l
	ld	%2 (%3),h
	ld	(hl),%4
	; peephole z88dk-182b
}
// if notVolatile()

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	add	a,#0x%1
	ld	hl,#%3
	ld	(hl),a
	ld	a,e
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	de,#0x%2%1
	add	hl,de
	ld	(#%3),hl
	ld	hl,#%3 + 1
	; peephole z88dk-183a
} if notUsed('de')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	add	a,#0x%1
	ld	hl,#%3
	ld	(hl),a
	ld	a,e
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	d,l
	ld	e,h
	ld	bc,#0x%2%1
	add	hl,bc
	ld	(#%3),hl
	ld	hl,#%3 + 1
	; peephole z88dk-183b
} if notUsed('bc')

replace restart {
	ld	e,l
	ld	d,h
	push	de
} by {
	push	hl
	; peephole z88dk-184a
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	push	bc
} by {
	push	hl
	; peephole z88dk-184b
} if notUsed('bc')

replace restart {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	sla	e
	rl	d
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-185a
} if notUsed('hl')

replace restart {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	sla	e
	rl	d
} by {
	ex	de,hl
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-185b
}

replace restart {
	ld	b,l
	ld	c,h
	pop	de
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
} by {
	ld	b,l
	ld	c,h
	pop	de
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-186
}

replace restart {
	inc	bc
	dec	bc
} by {
	; peephole z88dk-187a
}

replace restart {
	inc	de
	dec	de
} by {
	; peephole z88dk-187b
}

replace restart {
	inc	hl
	dec	hl
} by {
	; peephole z88dk-187c
}

replace restart {
	dec	bc
	inc	bc
} by {
	; peephole z88dk-188a
}

replace restart {
	dec	de
	inc	de
} by {
	; peephole z88dk-188b
}

replace restart {
	dec	hl
	inc	hl
} by {
	; peephole z88dk-188c
}

replace restart {
	dec	%1
	inc	%1
	inc	%1
} by {
	inc	%1
	; peephole z88dk-189a
} if notVolatile(%1)

replace restart {
	inc	%1
	dec	%1
	dec	%1
} by {
	dec	%1
	; peephole z88dk-189b
} if notVolatile(%1)

replace restart {
	sla	%2
	rl	%3
	ld	l, %2
	ld	h, %3
} by {
	ld	l, %2
	ld	h, %3
	add	hl,hl
	ld	%2, l
	ld	%3, h
	; peephole z88dk-190a
}

replace restart {
	ld	hl,#%1
	ld	%2,(hl)
	inc	hl
	ld	%3,(hl)
	ld	l, %2
	ld	h, %3
} by {
	ld	hl,(#%1)
	ld	%2, l
	ld	%3, h
	; peephole z88dk-190b
}

replace restart {
	push	hl
	ld	d,(hl)
	inc	hl
	ld	e,(hl)
	pop	hl
	ld	a,d
	add	a,#0x%1
	ld	d,a
	ld	a,e
	adc	a,#0x%2
	ld	e,a
	ld	(hl),d
	inc	hl
	ld	(hl),e
} by {
	push	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ld	hl,#0x%2%1
	add	hl,de
	ex	de,hl
	pop	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	; peephole z88dk-191a
} if notUsed('de')

replace restart {
	push	hl
	ld	d,(hl)
	inc	hl
	ld	e,(hl)
	pop	hl
	ld	a,d
	add	a,#0x%1
	ld	d,a
	ld	a,e
	adc	a,#0x%2
	ld	e,a
	ld	(hl),d
	inc	hl
	ld	(hl),e
} by {
	push	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ld	hl,#0x%2%1
	add	hl,de
	ld	d,l
	ld	e,h
	pop	hl
	ld	(hl),d
	inc	hl
	ld	(hl),e
	; peephole z88dk-191b
}

replace restart {
	ld	%1 (%5),%3
	ld	%2 (%5),%4
	sla	%1 (%5)
	rl	%2 (%5)
	ld	l,%1 (%5)
	ld	h,%2 (%5)
} by {
	ld	l,%3
	ld	h,%4
	add	hl,hl
	ld	%1 (%5),l
	ld	%2 (%5),h
	; peephole z88dk-192b
}

replace restart {
	sla	%1 (%5)
	rl	%2 (%5)
	ld	l,%1 (%5)
	ld	h,%2 (%5)
} by {
	ld	l,%1 (%5)
	ld	h,%2 (%5)
	add	hl,hl
	ld	%1 (%5),l
	ld	%2 (%5),h
	; peephole z88dk-192c
}

replace restart {
	ld	%1 (%5),%3
	ld	%2 (%5),%4
	ld	l,%1 (%5)
	ld	h,%2 (%5)
} by {
	ld	l,%3
	ld	h,%4
	ld	%1 (%5),l
	ld	%2 (%5),h
	; peephole z88dk-192d
}
// if notVolatile

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	ld	(#%1),bc
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	ld	c,l
	ld	b,h
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ld	hl,#%1 + 3
	; peephole z88dk-193
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	d,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	e,a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	d,l
	ld	e,h
	ld	a,h
	ld	hl,#%2 + 1
	; peephole z88dk-194
}

replace restart {
	push	hl
	ld	%1,(hl)
	inc	hl
	ld	%2,(hl)
	pop	hl
} by {
	ld	%1,(hl)
	inc	hl
	ld	%2,(hl)
	dec	hl
	; peephole z88dk-195a
}

replace restart {
	push	hl
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
	pop	hl
} by {
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
	dec	hl
	; peephole z88dk-195b
}

replace restart {
	push	hl
	ld	%1,(hl)
	dec	hl
	ld	%2,(hl)
	pop	hl
} by {
	ld	%1,(hl)
	dec	hl
	ld	%2,(hl)
	inc	hl
	; peephole z88dk-195c
}

replace restart {
	push	hl
	ld	(hl),%1
	dec	hl
	ld	(hl),%2
	pop	hl
} by {
	ld	(hl),%1
	dec	hl
	ld	(hl),%2
	inc	hl
	; peephole z88dk-195d
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	c,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	c,l
	ld	b,h
	ld	hl,#%2 + 1
	; peephole z88dk-196
}

replace restart {
	ld	%4,%1 + %2
	push	%3
	dec	%4
} by {
	push	%3
	ld	%4,%1 + %2
	dec	%4
	; peephole z88dk-197a  Warning may lead to incorrect code
} if notSame(%3 %4)

replace restart {
	ld	%4,%1 + %2
	push	%3
	inc	%4
} by {
	push	%3
	ld	%4,%1 + %2
	inc	%4
	; peephole z88dk-197b  Warning may lead to incorrect code
} if notSame(%3 %4)

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	add	hl,bc
} by {

	ld	bc,#%1
	add	hl,bc
	; peephole z88dk-198a
} if notUsed('bc')

replace restart {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	add	hl,de
} by {

	ld	de,#%1
	add	hl,de
	; peephole z88dk-198b
} if notUsed('de')

replace restart {
	ld	%1,l
	ld	%2,h
	pop	de
	ld	l,%1
	ld	h,%2
} by {
	ld	%1,l
	ld	%2,h
	pop	de
	; peephole z88dk-199
} if operandsNotRelated(%1 'de'), operandsNotRelated(%2 'de'), operandsNotRelated(%1 'hl'), operandsNotRelated(%2 'hl')
// if notVolatile()

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%2 + 1
	; peephole z88dk-200a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%2 + 1
	; peephole z88dk-200b
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	e,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-202a
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	e,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ex	de,hl
	ld	hl,#%2 + 1
	; peephole z88dk-202b
} if notUsed('a')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	c,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-202c
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	c,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	c,l
	ld	b,h
	ld	hl,#%2 + 1
	; peephole z88dk-202d
} if notUsed('a')

replace restart {
	ex	de,hl
	push	de
} by {
	push	hl
	; peephole z88dk-203a
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	push	de
} by {
	push	hl
	ex	de,hl
	; peephole z88dk-203b
}

replace restart {
	ld	c,l
	ld	b,h
	push	bc
} by {
	push	hl
	; peephole z88dk-203c
} if notUsed('bc')

replace restart {
	ld	c,l
	ld	b,h
	push	bc
} by {
	push	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-203d
}

replace restart {
	ld	e,l
	ld	d,h
	push	de
} by {
	push	hl
	; peephole z88dk-203e
} if notUsed('de')

replace restart {
	ld	e,l
	ld	d,h
	push	de
} by {
	push	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-203f
}

replace restart {
	ld	a,e
	ld	hl,#%1
	add	a, (hl)
	ld	e,a
	ld	a,d
	inc	hl
	adc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-204a
}

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a, (hl)
	ld	c,a
	ld	a,b
	inc	hl
	adc	a, (hl)
	ld	b,a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-204b
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	; peephole z88dk-205a
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	; peephole z88dk-205b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-205c
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-205d
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	sla	c
	rl	b
} by {
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-206a
} if notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	sla	c
	rl	b
} by {
	ld	e,l
	ld	d,h
	add	hl,hl
	ld	c,l
	ld	b,h
	ld	l,e
	ld	h,d
	; peephole z88dk-206b
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	ld	l,e
	ld	h,d
	sla	c
	rl	b
} by {
	add	hl,hl
	ld	c,l
	ld	b,h
	ld	l,e
	ld	h,d
	; peephole z88dk-206c
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	add	hl,bc
} by {
	ld	bc,#%1
	add	hl,bc
	; peephole z88dk-207a
} if notUsed('bc')

replace restart {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	add	hl,de
} by {
	ld	de,#%1
	add	hl,de
	; peephole z88dk-207b
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-208a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-208c
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	push	de
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	pop	de
	ld	hl,#%1 + 1
	; peephole z88dk-208e
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	(hl),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%2 + 1
	; peephole z88dk-209a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	(hl),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%2 + 1
	; peephole z88dk-209c
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	(hl),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(hl),a
} by {
	push	de
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%2),hl
	pop	de
	ld	hl,#%2 + 1
	; peephole z88dk-209e
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-210a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-210c
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	push	de
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%1),hl
	pop	de
	ld	hl,#%1 + 1
	; peephole z88dk-210e
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	(hl),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%2 + 1
	; peephole z88dk-211a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	(hl),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%2 + 1
	; peephole z88dk-211c
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-212a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-212c
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	push	de
	ld	hl,(#%1)
	ld	de,(#%2)
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	pop	de
	ld	hl,#%2 + 1
	; peephole z88dk-212e
}

replace restart {
	ld	a,c
	add	a, e
	ld	c,a
	ld	a,b
	adc	a, d
	ld	b,a
} by {
	ex	de,hl
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-213a
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	ld	a,c
	add	a, e
	ld	c,a
	ld	a,b
	adc	a, d
	ld	b,a
} by {
	ld	e,l
	ld	d,h
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-213b
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),#<(%2)
	inc	hl
	ld	(hl),#>(%2)
} by {
	ld	hl,#%2
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-215
}

replace restart {
	ld	hl,#%1 + 1
	ld	d,(hl)
	dec	hl
	ld	e,(hl)
} by {
	ld	de,(#%1)
	ld	hl,#%1
	; peephole z88dk-216a
}

replace restart {
	ld	hl,#%1 + 1
	ld	b,(hl)
	dec	hl
	ld	c,(hl)
} by {
	ld	bc,(#%1)
	ld	hl,#%1
	; peephole z88dk-216c
}

replace restart {
	ld	(#%1),hl
	ld	de,(#%1)
} by {
	ld	(#%1),hl
	ex	de,hl
	; peephole z88dk-217a
} if notUsed('hl'), notVolatile(%1)

replace restart {
	ld	(#%1),hl
	ld	de,(#%1)
} by {
	ld	(#%1),hl
	ld	e,l
	ld	d,h
	; peephole z88dk-217b
} if notVolatile(%1)

replace restart {
	ex	de,hl
	ld	a,%1 (%3)
	add	a, e
	ld	e,a
	ld	a,%2 (%3)
	adc	a, d
	ld	d,a
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	add	hl,de
	ex	de,hl
	; peephole z88dk-218a
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	a,%1 (%3)
	add	a, e
	ld	e,a
	ld	a,%2 (%3)
	adc	a, d
	ld	d,a
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,de
	ex	de,hl
	; peephole z88dk-218b
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,%1 (%3)
	add	a, d
	ld	d,a
	ld	a,%2 (%3)
	adc	a, e
	ld	e,a
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	add	hl,de
	ld	e,h
	ld	d,l
	; peephole z88dk-218c
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	a,%1 (%3)
	add	a, d
	ld	d,a
	ld	a,%2 (%3)
	adc	a, e
	ld	e,a
} by {
	ld	h,e
	ld	l,d
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	add	hl,de
	ld	e,h
	ld	d,l
	; peephole z88dk-218d
	; increases code size but may allow more substitutions
} if notUsed('hl'), notUsed('a')

replace restart {
	ex	de,hl
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,de
	ex	de,hl
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	add	hl,de
	ex	de,hl
	; peephole z88dk-219a
} if notUsed('hl')

replace restart {
	ex	de,hl
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,de
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	add	hl,de
	; peephole z88dk-219b
} if notUsed('de')

replace restart {
	ld	a,%1 (%7)
	add	a, #0x%3
	ld	c,a
	ld	a,%2 (%7)
	adc	a, #0x%4
	ld	b,a
	ld	%5 (%7),c
	ld	%6 (%7),b
} by {
	ld	l,%1 (%7)
	ld	h,%2 (%7)
	ld	bc,#0x%4%3
	add	hl,bc
	ld	%5 (%7),l
	ld	%6 (%7),h
	; peephole z88dk-220
} if notUsed('hl'), notUsed('a'), notUsed('bc')

replace restart {
	ld	%1 (%3),l
	ld	%2 (%3),h
	sla	%1 (%3)
	rl	%2 (%3)
} by {
	add	hl,hl
	ld	%1 (%3),l
	ld	%2 (%3),h
	; peephole z88dk-221
} if notUsed('hl')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,%3 (%5)
	add	a, d
	ld	%1 (%5),a
	ld	a,%4 (%5)
	adc	a, e
	ld	%2 (%5),a
} by {
	ld	e,%3 (%5)
	ld	d,%4 (%5)
	add	hl,de
	ld	%1 (%5),l
	ld	%2 (%5),h
	; peephole z88dk-222
} if notUsed('hl'), notUsed('de'), notUsed('a')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	dec	hl
	or	a,(hl)
} by {
	ld	hl,(#%1 + %2 - 1)
	ld	a,h
	or	a,l
	; peephole z88dk-223
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	(#%3),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	(#%3 + 1),a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%3),hl
	ld	hl,#%2 + 1
	; peephole z88dk-224a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	(#%3),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	(#%3 + 1),a
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%3),hl
	ld	hl,#%2 + 1
	; peephole z88dk-224b
} if notUsed('bc')

replace restart {
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sbc	a, (hl)
	ld	(#%3 + 2),a
	ld	a,(#%1 + 3)
	ld	hl,#%2 + 3
	sbc	a, (hl)
	ld	(#%3 + 3),a
} by {
	ld	hl,(#%1 + 2)
	ld	de,(#%2 + 2)
	sbc	hl,de
	ld	a,h
	ld	(#%3 + 2),hl
	ld	hl,#%2 + 3
	; peephole z88dk-225a
} if notUsed('de')

replace restart {
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sbc	a, (hl)
	ld	(#%3 + 2),a
	ld	a,(#%1 + 3)
	ld	hl,#%2 + 3
	sbc	a, (hl)
	ld	(#%3 + 3),a
} by {
	ld	hl,(#%1 + 2)
	ld	bc,(#%2 + 2)
	sbc	hl,bc
	ld	a,h
	ld	(#%3 + 2),hl
	ld	hl,#%2 + 3
	; peephole z88dk-225b
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	(#%2 + 0),a
	inc	hl
	ld	a,(hl)
	ld	(#%2 + 1),a
	inc	hl
	ld	a,(hl)
	ld	(#%2 + 2),a
	inc	hl
	ld	a,(hl)
	ld	(#%2 + 3),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	a,h
	ld	hl,#%1 + 3
	; peephole z88dk-226
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	(#%2 + 0),a
	inc	hl
	ld	a,(hl)
	ld	(#%2 + 1),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-226c
}

replace restart {
	ld	de,#%1
	ld	a,(de)
	ld	hl,#%2
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%1 + 2)
	ld	(#%2 + 2),hl
	ld	a,h
	ld	de,#%1 + 3
	ld	hl,#%2 + 3
	; peephole z88dk-227
}

replace restart {
	ld	de,#%1
	ld	a,(de)
	ld	hl,#%2
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	a,h
	ld	de,#%1 + 1
	ld	hl,#%2 + 1
	; peephole z88dk-227e
}

replace restart {
	ld	hl,#%1
	ld	(hl),a
} by {
	ld	(#%1),a
	; peephole z88dk-227i
} if notUsed('hl')

replace restart {
	ld	bc,(#%1)
	ld	b,%2
} by {
	ld	a,(#%1)
	ld	c,a
	ld	b,%2
	; peephole z88dk-228a
} if notUsed('a')

replace restart {
	ld	de,(#%1)
	ld	d,%2
} by {
	ld	a,(#%1)
	ld	e,a
	ld	d,%2
	; peephole z88dk-228b
} if notUsed('a')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	%3,a
	ld	a,#>(%1)
	adc	a, %5
	ld	%4,a
} by {
	ld	a,(#%2)
	add	a,#<(%1)
	ld	%3,a
	ld	a,#>(%1)
	adc	a, %5
	ld	%4,a
	; peephole z88dk-229
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	d,(hl)
	inc	hl
	ld	e,(hl)
	ld	hl,#%2
	ld	(hl),d
	inc	hl
	ld	(hl),e
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	d,l
	ld	e,h
	ld	hl,#%1 + 2
	; peephole z88dk-230
}

replace restart {
	ld	%2,l
	ld	%3,h
	ld	hl,#%1
	ld	(hl),%2
	inc	hl
	ld	(hl),%3
} by {
	ld	(#%1),hl
	ld	%2,l
	ld	%3,h
	ld	hl,#%1 + 1
	; peephole z88dk-231
}

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%2 + 1
	; peephole z88dk-232a
}

replace restart {
	ld	hl,#%2 + %1
	sla	(hl)
	inc	hl
	rl	(hl)
} by {
	ld	hl,(#%2 + %1)
	add	hl,hl
	ld	(#%2 + %1),hl
	; peephole z88dk-232b
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	sla	(hl)
	inc	hl
	rl	(hl)
} by {
	ld	hl,(#%1)
	add	hl,hl
	ld	(#%1),hl
	; peephole z88dk-232c
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	ld	(hl),a
	ld	a,#%5
	jp	%3
%4:
	dec	hl
	sla	(hl)
	inc	hl
	rl	(hl)
%3:
	dec	a
	jp	NZ,%4
} by {
	ld	hl,(#%1)
	z88dk_sll hl,%5
	ld	(#%2),hl
	ld	a,#0x00
	ld	hl,#%2 + 1
	; peephole z88dk-232e
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2 + 1
	ld	(hl),a
	dec	hl
	ld	(hl),#%3
} by {
	ld	a,(#%1)
	ld	h,a
	ld	l,#%3
	ld	(#%2),hl
	; peephole z88dk-232g
} if notUsed('hl')

replace restart {
	ld	a,(#%1 + 0)
	ld	(#%2 + 0),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
	ld	iy,#%2
	sla	0 (iy)
	ld	iy,#%2
	rl	1 (iy)
} by {
	ld	hl,(#%1)
	ld	a,h
	add	hl,hl
	ld	(#%2),hl
	; peephole z88dk-233a
} if notUsed('hl'), notUsed('iy')

replace restart {
	ld	a,(#%1 + 0)
	ld	(#%2 + 0),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
	ld	iy,#%2
	sla	0 (iy)
	ld	iy,#%2
	rl	1 (iy)
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	a,h
	add	hl,hl
	ld	(#%2),hl
	ex	de,hl
	; peephole z88dk-233b
} if notUsed('de'), notUsed('iy')

replace restart {
	ld	a,(#%1 + 0)
	ld	(#%2 + 0),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
	ld	iy,#%2
	sla	0 (iy)
	ld	iy,#%2
	rl	1 (iy)
} by {
	push	hl
	ld	hl,(#%1)
	ld	a,h
	add	hl,hl
	ld	(#%2),hl
	pop	hl
	; peephole z88dk-233c
} if notUsed('iy')

replace restart {
	ld	a,(#%1 + 0)
	ld	(#%2 + 0),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
	ld	a,#%5
	jp	%3
%4:
	ld	iy,#%2
	sla	0 (iy)
	ld	iy,#%2
	rl	1 (iy)
%3:
	dec	a
	jp	NZ,%4
} by {
	ld	hl,(#%1)
	z88dk_sll hl,%5
	ld	(#%2),hl
	ld	a,#0x00
	; peephole z88dk-233d
} if notUsed('hl'), notUsed('iy')

replace restart {
	ld	a,(#%1 + 0)
	ld	(#%2 + 0),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
	ld	a,#%5
	jp	%3
%4:
	ld	iy,#%2
	sla	0 (iy)
	ld	iy,#%2
	rl	1 (iy)
%3:
	dec	a
	jp	NZ,%4
} by {
	ex	de,hl
	ld	hl,(#%1)
	z88dk_sll hl,%5
	ld	(#%2),hl
	ld	a,#0x00
	ex	de,hl
	; peephole z88dk-233e
} if notUsed('de'), notUsed('iy')

replace restart {
	ld	a,(#%1 + 0)
	ld	(#%2 + 0),a
	ld	a,(#%1 + 1)
	ld	(#%2 + 1),a
	ld	a,#%5
	jp	%3
%4:
	ld	iy,#%2
	sla	0 (iy)
	ld	iy,#%2
	rl	1 (iy)
%3:
	dec	a
	jp	NZ,%4
} by {
	push	hl
	ld	hl,(#%1)
	z88dk_sll hl,%5
	ld	(#%2),hl
	ld	a,#0x00
	pop	hl
	; peephole z88dk-233f
} if notUsed('iy')

replace restart {
	ld	a,(#%1)
	add	a, e
	ld	(#%2),a
	ld	a,(#%1 + 1)
	adc	a, d
	ld	(#%2 + 1),a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	a,h
	ld	(#%2),hl
	; peephole z88dk-235a
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	add	a, c
	ld	(#%2),a
	ld	a,(#%1 + 1)
	adc	a, b
	ld	(#%2 + 1),a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	(#%2),hl
	; peephole z88dk-235b
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	c,a
	ld	a,#>(%1)
	inc	hl
	adc	a, (hl)
	ld	b,a
} by {
	ld	bc,#%1
	ld	hl,(#%2)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-236a
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	e,a
	ld	a,#>(%1)
	inc	hl
	adc	a, (hl)
	ld	d,a
} by {
	ld	de,#%1
	ld	hl,(#%2)
	add	hl,de
	ld	a,h
	ld	e,l
	ld	d,h
	; peephole z88dk-236b
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	(#%2),a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	ld	(hl),a
	srl	(hl)
	dec	hl
	rr	(hl)
} by {
	ld	hl,(#%1)
	ld	a,h
	srl	h
	rr	l
	ld	(#%2),hl
	ld	hl,#%2
	; peephole z88dk-237a
}

replace restart {
	ld	hl,#%2
	inc	hl
	srl	(hl)
	dec	hl
	rr	(hl)
} by {
	ld	hl,(#%2)
	srl	h
	rr	l
	ld	(#%2),hl
	ld	hl,#%2
	; peephole z88dk-237c
}

replace restart {
	ld	hl,#%1 + 1
	ld	(#%1),de
	sra	(hl)
	dec	hl
	rr	(hl)
} by {
	ld	l,e
	ld	h,d
	sra	h
	rr	l
	ld	(#%1),hl
	ld	hl,#%1
	; peephole z88dk-238a
}

replace restart {
	ld	hl,#%1
	inc	hl
	sra	(hl)
	dec	hl
	rr	(hl)
} by {
	ld	hl,(#%1)
	sra	h
	rr	l
	ld	(#%1),hl
	ld	hl,#%1
	; peephole z88dk-238b
}

replace restart {
	ld	a,(#%1 + 1)
	ld	hl,#%2
	ld	(hl),a
	inc	hl
	ld	(hl),#%3
} by {
	ld	hl,(#%1 + 1)
	ld	a,l
	ld	h,#%3
	ld	(#%2),hl
	; peephole z88dk-239
} if notUsed('hl')

replace restart {
	ld	(hl),%1
	ld	%1,(hl)
} by {
	ld	(hl),%1
	; peephole z88dk-240
}
// if notVolatile

replace restart {
	ld	b,l
	ld	c,h
	pop	de
} by {
	pop	de
	ld	b,l
	ld	c,h
	; peephole z88dk-241
}

replace restart {
	ld	%1,l
	ld	%2,h
	ld	a,%2
	or	a,%1
} by {
	ld	a,h
	or	a,l
	; peephole z88dk-242
} if notUsed(%1), notUsed(%2)

replace restart {
	ld	a,#0x10
%1:
	srl	c
	rr	b
	rr	d
	rr	e
	dec	a
	%2	NZ,%1
} by {
	ld	d,c
	ld	e,b
	xor	a,a
	ld	c,a
	ld	b,a
	; peephole z88dk-243a
}

replace restart {
	ld	b,#0x0F
%1:
	sra	d
	rr	e
	rr	h
	rr	l
	djnz	%1
} by {
	rl	h
	ex	de,hl
	adc	hl,hl
	sbc	a,a
	ld	e,a
	ld	d,a
	ld	b,#0x00
	; peephole z88dk-243b1
} if notUsed('a')

replace restart {
	ld	b,#0x0F
%1:
	sra	d
	rr	e
	rr	h
	rr	l
	djnz	%1
} by {
	ld	b,a
	rl	h
	ex	de,hl
	adc	hl,hl
	sbc	a,a
	ld	e,a
	ld	d,a
	ld	a,b
	ld	b,#0x00
	; peephole z88dk-243b2
}

replace restart {
	ld	b,#0x10
%1:
	sra	l
	rr	c
	rr	d
	rr	e
	djnz	%1
} by {
	ld	d,l
	ld	e,c
	ld	a,l
	add	a,a
	sbc	a,a
	ld	l,a
	ld	c,a
	ld	b,#0x00
	; peephole z88dk-243b3
}

replace restart {
	ld	b,#0x0F
%1:
	srl	d
	rr	e
	rr	h
	rr	l
	djnz	%1
} by {
	rl	h
	ex	de,hl
	adc	hl,hl
	ld	e,#0x00
	ld	d,e
	ld	b,e
	rl	e
	; peephole z88dk-244
}

replace restart {
	ld	a,l
	add	a,#0x%1
	ld	e,a
	ld	a,h
	adc	a,#0x%2
	ld	d,a
} by {
	ld	de,#0x%2%1
	add	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-245a
} if notUsed('hl')

replace restart {
	ld	a,l
	add	a,#0x%1
	ld	e,a
	ld	a,h
	adc	a,#0x%2
	ld	d,a
} by {
	ex	de,hl
	ld	hl,#0x%2%1
	add	hl,de
	ex	de,hl
	; peephole z88dk-245b
} if notUsed('a')

replace restart {
	ld	hl,#%2
	ld	a,(hl)
	sub	a, c
	jp	NZ,%1
	inc	hl
	ld	a,(hl)
	sub	a, b
	jp	NZ,%1
} by {
	ld	hl,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	jp	NZ,%1
	; peephole z88dk-246
} if notUsed('hl')

replace restart {
	ld	a,(de)
	ld	hl,#%1
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ex	de,hl
	ld	de,#%1
	ldi
	ld	a,(hl)
	ld	(de),a
	; peephole z88dk-247a
} if notUsed('bc'), notUsed('de'), notUsed('hl')

replace restart {
	ld	a,(de)
	ld	hl,#%1
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ex	de,hl
	ld	de,#%1
	ldi
	ld	a,(hl)
	ld	(de),a
	ex	de,hl
	; peephole z88dk-247b
} if notUsed('bc')

replace restart {
	ld	a,(de)
	ld	hl,#%1
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ex	de,hl
	ld	de,#%1
	ldi
	inc	bc
	ld	a,(hl)
	ld	(de),a
	; peephole z88dk-247c
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	a,(de)
	ld	hl,#%1
	ld	(hl),a
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ex	de,hl
	ld	de,#%1
	ldi
	inc	bc
	ld	a,(hl)
	ld	(de),a
	ex	de,hl
	; peephole z88dk-247d
}

replace restart {
	ld	%1,(hl)
	ld	a,%1
} by {
	ld	a,(hl)
	; peephole z88dk-248
} if notUsed(%1)

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	e,a
	ld	a,#>(%1)
	adc	a, h
	ld	d,a
} by {
	ld	de,#%1
	add	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-249a
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	e,a
	ld	a,#>(%1)
	adc	a, h
	ld	d,a
} by {
	ex	de,hl
	ld	hl,#%1
	add	hl,de
	ex	de,hl
	; peephole z88dk-249b
} if notUsed('a')

replace restart {
	ld	%1,(hl)
	ld	%2,(hl)
} by {
	ld	%1,(hl)
	ld	%2,%1
	; peephole z88dk-250
}
// if notVolatile

replace restart {
	ld	a,l
	sub	a, e
	ld	c,a
	ld	a,h
	sbc	a, d
	ld	b,a
} by {
	xor	a,a
	sbc	hl,de
	ld	c,l
	ld	b,h
	; peephole z88dk-251a
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	a,e
	sub	a, l
	ld	l,a
	ld	a,d
	sbc	a, h
	ld	h,a
} by {
	ex	de,hl
	xor	a,a
	sbc	hl,de
	; peephole z88dk-251b
} if notUsed('de')

replace restart {
	ld	a,#0x%1
	sub	a, e
	ld	l,a
	ld	a,#0x%2
	sbc	a, d
	ld	h,a
} by {
	ld	hl,#0x%2%1
	xor	a,a
	sbc	hl,de
	; peephole z88dk-252a
} if notUsed('a')

replace restart {
	ld	a,#0x%1
	sub	a, c
	ld	l,a
	ld	a,#0x%2
	sbc	a, b
	ld	h,a
} by {
	ld	hl,#0x%2%1
	xor	a,a
	sbc	hl,bc
	; peephole z88dk-252b
} if notUsed('a')

replace restart {
	ld	c,%1 (%3)
	ld	b,%2 (%3)
	sla	c
	rl	b
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-253a
} if notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	sla	c
	rl	b
} by {
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-253b
} if notUsed('hl')

replace restart {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	sla	e
	rl	d
} by {
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-253c
} if notUsed('hl')

replace restart {
	ex	de,hl
	sla	e
	rl	d
} by {
	add	hl,hl
	ex	de,hl
	; peephole z88dk-253d
}

replace restart {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	sla	e
	rl	d
} by {
	ex	de,hl
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,hl
	ex	de,hl
	; peephole z88dk-253e
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	add	hl,bc
} by {
	ld	bc,#%1
	add	hl,bc
	; peephole z88dk-254a
} if notUsed('bc')

replace restart {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	add	hl,de
} by {
	ld	de,#%1
	add	hl,de
	; peephole z88dk-254b
} if notUsed('de')

replace restart {
	pop	de
	push	de
	sla	e
	rl	d
} by {
	pop	hl
	push	hl
	add	hl,hl
	ex	de,hl
	; peephole z88dk-255a
} if notUsed('hl')

replace restart {
	pop	bc
	push	bc
	sla	c
	rl	b
} by {
	pop	hl
	push	hl
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-255b
} if notUsed('hl')

replace restart {
	ex	de,hl
	ld	l,%1 (%3)
	ld	h,%2 (%3)
	add	hl,de
} by {
	ld	e,%1 (%3)
	ld	d,%2 (%3)
	add	hl,de
	; peephole z88dk-256
} if notUsed('de')

replace restart {
	sla	d
	rl	e
	sla	d
	rl	e
} by {
	ld	l,d
	ld	h,e
	add	hl,hl
	add	hl,hl
	ld	d,l
	ld	e,h
	; peephole z88dk-257a
} if notUsed('hl')

replace restart {
	ld	d,l
	ld	e,h
	sla	d
	rl	e
} by {
	add	hl,hl
	ld	d,l
	ld	e,h
	; peephole z88dk-257b
} if notUsed('hl')

replace restart {
	sla	d
	rl	e
	ld	h,e
	ld	l,d
} by {
	ld	l,d
	ld	h,e
	add	hl,hl
	; peephole z88dk-257c
} if notUsed('de')

replace restart {
	ld	a,c
	add	a, e
	ld	e,a
	ld	a,b
	adc	a, d
	ld	d,a
} by {
	ex	de,hl
	add	hl,bc
	ex	de,hl
	ld	a,d
	; peephole z88dk-258a
}

replace restart {
	pop	bc
	ld	a,c
	add	a,e
	ld	c,a
	ld	a,b
	adc	a,d
	ld	b,a
} by {
	pop	hl
	add	hl,de
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-258b
} if notUsed('hl')

replace restart {
	ld	%1,(hl)
	ld	(hl),%1
} by {
	ld	%1,(hl)
	; peephole z88dk-260
} // if notVolatile

replace restart {
	ld	%1,(%2)
} by {
	; peephole z88dk-261
} if notUsed(%1) 
//, notVolatile

replace restart {
	ld	e,h
	ld	d,l
	ld	l, d
	ld	h, e
} by {
	ld	e,h
	ld	d,l
	; peephole z88dk-262a
}

replace restart {
	ld	d,c
	ld	e,b
	ld	l,d
	ld	h,e
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-262b
} if notUsed('de')

replace restart {
	ld	a,#0x%1
	ld	hl,#%3
	sub	a, (hl)
	ld	d,a
	ld	a,#0x%2
	inc	hl
	sbc	a, (hl)
	ld	e,a
} by {
	ld	hl,#0x%2%1
	ld	de,(#%3)
	xor	a,a
	sbc	hl,de
	ld	e,h
	ld	d,l
	; peephole z88dk-263
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	a, l
	ld	hl,#%1
	sub	a, (hl)
	ld	d,a
	ld	a,e
	inc	hl
	sbc	a, (hl)
	ld	e,a
} by {
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	e,h
	ld	d,l
	; peephole z88dk-264
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	add	a, (hl)
	ld	d,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	e,a
} by {
	ld	de,(#%1)
	ld	hl,(#%2)
	add	hl,de
	ld	a,h
	ld	e,h
	ld	d,l
	ld	hl,#%2 + 1
	; peephole z88dk-265
} 

replace restart {
	ld	a,#0x%1
	ld	hl,#%3
	sub	a, (hl)
	ld	e,a
	ld	a,#0x%2
	inc	hl
	sbc	a, (hl)
	ld	d,a
} by {
	ld	de,(#%3)
	ld	hl,#0x%2%1
	xor	a,a
	sbc	hl,de
	ex	de,hl
	; peephole z88dk-266
} if notUsed('a'), notUsed('hl')
	
replace restart {
	ld	a,#0x%1
	sub	a, e
	ld	e,a
	ld	a,#0x%2
	sbc	a, d
	ld	d,a
} by {
	ld	hl,#0x%2%1
	xor	a,a
	sbc	hl,de
	ex	de,hl
	; peephole z88dk-267
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	%1,#0
	add	%1,sp
	ld	0 (%1),d
	ld	1 (%1),e
} by {
	ld	a,e
	ld	e,d
	ld	d,a
	pop	af
	push	de
	ld	a,e
	ld	e,d
	ld	d,a
	; peephole z88dk-268
} if notUsed('a')

replace restart {
	push	hl
	ld	a,h
	ld	%1,#%2
	add	%1,sp
	ld	0 (%1),a
	pop	hl
	push	hl
	ld	1 (%1), l
	pop	hl
} by {
	ld	a,h
	ex	de,hl
	ld	hl,#%2
	add	hl,sp
	ld	(hl),d
	inc	hl
	ld	(hl),e
	ex	de,hl
	; peephole z88dk-269a
} if notUsed('de')

replace restart {
	push	hl
	ld	a,h
	ld	%1,#%2
	add	%1,sp
	ld	0 (%1),a
	pop	hl
	push	hl
	ld	1 (%1), l
	pop	hl
} by {
	ld	c,l
	ld	a,h
	ld	hl,#%2
	add	hl,sp
	ld	(hl),a
	inc	hl
	ld	(hl),c
	ld	l,c
	ld	h,a
	; peephole z88dk-269b
} if notUsed('c')

replace restart {
	push	hl
	ld	a,h
	ld	%1,#%2
	add	%1,sp
	ld	0 (%1),a
	pop	hl
	push	hl
	ld	1 (%1), l
	pop	hl
} by {
	ld	a,h
	push	de
	ex	de,hl
	ld	hl,#%2
	add	hl,sp
	ld	(hl),d
	inc	hl
	ld	(hl),e
	ex	de,hl
	pop	de
	; peephole z88dk-269c
}

replace restart {
	ld	b,e
	ld	c,d
	sla	b
	rl	c
} by {
	ld	l,e
	ld	h,d
	add	hl,hl
	ld	b,l
	ld	c,h
	; peephole z88dk-270a
} if notUsed('hl')

replace restart {
	ld	b,l
	ld	c,h
	sla	b
	rl	c
} by {
	add	hl,hl
	ld	b,l
	ld	c,h
	; peephole z88dk-270b
} if notUsed('hl')

replace restart {
	ld	b,l
	ld	c,h
	ld	a,%1 (%3)
	add	a, b
	ld	b,a
	ld	a,%2 (%3)
	adc	a, c
	ld	c,a
	ld	l, b
	ld	h, c
} by {
	ld	c,%1 (%3)
	ld	b,%2 (%3)
	add	hl,bc
	ld	a,h
	ld	c,h
	ld	b,l
	; peephole z88dk-270c
} 

replace restart {
	ld	a,e
	add	a,#0x%1
	ld	c,a
	ld	a,d
	adc	a,#0x%2
	ld	b,a
} by {
	ld	hl,#0x%2%1
	add	hl,de
	ld	c,l
	ld	b,h
	; peephole z88dk-271
} if notUsed('hl')

//replace restart {
//	ld	hl,#%1
//	ld	(hl),#%2
//} by {
//	ld	a,#%2
//	ld	(#%1),a
//	; peephole z88dk-273
//} if notUsed('a'), notUsed('hl')

replace restart {
	ld	hl,#%3
	ld	%1,(hl)
	inc	hl
	ld	%2,(hl)
} by {
	ld	hl,(#%3)
	ld	%1,l
	ld	%2,h
	; peephole z88dk-274a
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),d
	inc	hl
	ld	(hl),e
} by {
	ld	l,d
	ld	h,e
	ld	(#%1),hl
	; peephole z88dk-274b
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	(hl),b
	inc	hl
	ld	(hl),c
} by {
	ld	l,b
	ld	h,c
	ld	(#%1),hl
	; peephole z88dk-274c
} if notUsed('hl')

replace restart {
	sla	c
	rl	b
	ld	a,%1 (%3)
	add	a, c
	ld	c,a
	ld	a,%2 (%3)
	adc	a, b
	ld	b,a
	ld	l, c
	ld	h, b
} by {
	ld	l,c
	ld	h,b
	add	hl,hl
	ld	c,%1 (%3)
	ld	b,%2 (%3)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-275
}

replace restart {
	ld	b,l
	ld	c,h
	ld	a,%1 (%3)
	add	a, b
	ld	b,a
	ld	a,%2 (%3)
	adc	a, c
	ld	c,a
	ld	l, b
	ld	h, c
} by {
	ld	c,%1 (%3)
	ld	b,%2 (%3)
	add	hl,bc
	ld	a,h
	ld	b,l
	ld	c,h
	; peephole z88dk-276
}

replace restart {
	ld	l, c
	ld	h, b
	add	hl, hl
	ld	a,#<(%1)
	add	a, l
	ld	l,a
	ld	a,#>(%1)
	adc	a, h
	ld	h,a
} by {
	ld	hl,#%1
	add	hl,bc
	add	hl,bc
	ld	a,h
	; peephole z88dk-277
}

replace restart {
	ld	l, e
	ld	h, d
	inc	de
	ld	a,#<(%1)
	add	a, l
	ld	l,a
	ld	a,#>(%1)
	adc	a, h
	ld	h,a
} by {
	ld	hl,#%1
	add	hl,de
	ld	a,h
	inc	de
	; peephole z88dk-278
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%3
	add	a, (hl)
	ld	e,a
	ld	a,#>(%1)
	inc	hl
	adc	a, (hl)
	ld	d,a
} by {
	ld	hl,(#%3)
	ld	de,#%1
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%3 + 1
	; peephole z88dk-279
}

replace restart {
	ex	de,hl
	ld	hl,#%1
	ld	a,(de)
} by {
	ld	a,(hl)
	ld	hl,#%1
	; peephole z88dk-280a
} if notUsed('de')

replace restart {
	ex	de,hl
	ld	hl,#%1 + %2
	ld	a,(de)
} by {
	ld	a,(hl)
	ld	hl,#%1 + %2
	; peephole z88dk-280b
} if notUsed('de')

replace restart {
	ld	a,(hl)
	ld	(#%1),a
	ld	a,(#%2 + 1)
	ld	hl,#%1 + 1
	ld	(hl),a
} by {
	ld	hl,(#%2)
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-281  Warning may lead to incorrect code
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, #0x%2
	inc	hl
	ld	a,(hl)
	sbc	a, #0x%3
	jp	%4,%5
	ld	a,#<(%6)
	dec	hl
} by {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, #0x%2
	inc	hl
	ld	a,(hl)
	sbc	a, #0x%3
	jp	%4,%5
	ld	a,#<(%6)
	ld	hl,#%1
	; peephole z88dk-283
}

replace restart {
	ld	hl,#%1 + 1
	ld	a,%2
	ld	(de),a
	dec	hl
} by {
	ld	a,%2
	ld	(de),a
	ld	hl,#%1
	; peephole z88dk-284
} if notSame(%2 'h' 'l' 'hl' '(hl)')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, %2 (ix)
	inc	hl
	ld	a,(hl)
	sbc	a, %3 (ix)
} by {
	ld	hl,(#%1)
	ld	a,l
	sub	a, %2 (ix)
	ld	a,h
	sbc	a, %3 (ix)
	; peephole z88dk-286
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + 1
	inc	hl
} by {
	ld	hl,#%1 + 2
	; peephole z88dk-287a
}

replace restart {
	ld	hl,#%1 + 1
	dec	hl
} by {
	ld	hl,#%1
	; peephole z88dk-287b
}

replace restart {
	ld	hl,#%1
	rl	(hl)
	inc	hl
	rl	(hl)
} by {
	ld	hl,(#%1)
	adc	hl,hl
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-288a
}

replace restart {
	ld	hl,#%1 + 1
	dec	hl
	rl	(hl)
	inc	hl
	rl	(hl)
} by {
	ld	hl,(#%1)
	adc	hl,hl
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-288b
}

replace restart {
	ld	b,#%1
%2:
	ld	hl,(#%3)
	add	hl,hl
	ld	(#%3),hl
	ld	hl,(#%3 + 2)
	adc	hl,hl
	ld	(#%3 + 2),hl
	djnz	%2
} by {
	ld	b,#%1
%2:
	ld	hl,(#%3)
	ld	de,(#%3 + 2)
lz_%2:
	add	hl,hl
	rl	e
	rl	d
	djnz	lz_%2
	ld	(#%3),hl
	ld	(#%3 + 2),de
	ex	de,hl
	; peephole z88dk-289a
} if notUsed('de')
//, notVolatile

replace restart {
	ld	b,#%1
%2:
	ld	hl,(#%3)
	add	hl,hl
	ld	(#%3),hl
	ld	hl,(#%3 + 2)
	adc	hl,hl
	ld	(#%3 + 2),hl
	djnz	%2
} by {
	ld	b,#%1
%2:
	push	de
	ld	hl,(#%3)
	ld	de,(#%3 + 2)
lz_%2:
	add	hl,hl
	rl	e
	rl	d
	djnz	lz_%2
	ld	(#%3),hl
	ld	(#%3 + 2),de
	ex	de,hl
	pop	de
	; peephole z88dk-289b
}
// if notVolatile

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sbc	a, (hl)
	ld	a,(#%1 + 3)
	ld	hl,#%2 + 3
	sbc	a, (hl)
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	hl,(#%1 + 2)
	ld	de,(#%2 + 2)
	sbc	hl,de
	ld	a,h
	ld	hl,#%2 + 3
	; peephole z88dk-290a
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sbc	a, (hl)
	ld	a,(#%1 + 3)
	ld	hl,#%2 + 3
	sbc	a, (hl)
} by {
	ld	hl,(#%1)
	ld	bc,(#%2)
	xor	a,a
	sbc	hl,bc
	ld	hl,(#%1 + 2)
	ld	bc,(#%2 + 2)
	sbc	hl,bc
	ld	a,h
	ld	hl,#%2 + 3
	; peephole z88dk-290b
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	ld	%3,(#%2)
	inc	hl
	ld	%4,(hl)
} by {
	ld	%3,(#%2)
	ld	hl,#%1 + 1
	ld	%4,(hl)
	; peephole z88dk-291a
} if notSame(%3 'hl')

replace restart {
	ld	hl,#%1 + 1
	ld	%3,(#%2)
	inc	hl
	ld	%4,(hl)
} by {
	ld	%3,(#%2)
	ld	hl,#%1 + 2
	ld	%4,(hl)
	; peephole z88dk-291b
} if notSame(%3 'hl')

replace restart {
	ld	hl,#%1
	ld	%3,(#%2)
	dec	hl
	ld	%4,(hl)
} by {
	ld	%3,(#%2)
	ld	hl,#%1 - 1
	ld	%4,(hl)
	; peephole z88dk-291c
} if notSame(%3 'hl')

replace restart {
	ld	hl,#%1 + 1
	ld	%3,(#%2)
	dec	hl
	ld	%4,(hl)
} by {
	ld	%3,(#%2)
	ld	hl,#%1
	ld	%4,(hl)
	; peephole z88dk-291d
} if notSame(%3 'hl')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	d,a
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	e,a
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	d,l
	ld	e,h
	ld	hl,#%2 + 1
	; peephole z88dk-292
}

replace restart {
	ld	hl,#%1 + 1
	ld	%2,%3
	dec	hl
} by {
	ld	%2,%3
	ld	hl,#%1
	; peephole z88dk-293
} if operandsNotRelated(%2 'hl'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	h,e
	ld	l,d
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-294a
} if notUsed('de')

replace restart {
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	h,e
	ld	l,d
	ld	bc,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-294b
} if notUsed('bc')

replace restart {
	ld	%3,(#%1)
	add	hl,%3
	ld	(#%2),%4
	ld	%3,(#%1)
} by {
	ld	%3,(#%1)
	add	hl,%3
	ld	(#%2),%4
	; peephole z88dk-295a
} if notSame(%1 %2), notSame(%3 'hl')
// if notVolatile

replace restart {
	ld	(#%1),%2
	ld	%2,(#%1)
} by {
	ld	(#%1),%2
	; peephole z88dk-295b
}
// if notVolatile

replace restart {
	ld	(#%1),hl
	ld	hl,(#%2)
	ld	de,(#%1)
} by {
	ld	(#%1),hl
	ex	de,hl
	ld	hl,(#%2)
	; peephole z88dk-295d
}
// if notVolatile

replace restart {
	ld	%4,%2 (%1)
	ld	%5,%3 (%1)
	ld	l, %4
	ld	h, %5
} by {
	ld	l,%2 (%1)
	ld	h,%3 (%1)
	; peephole z88dk-296
} if notUsed(%4), notUsed(%5)

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	c,a
	ld	a,#>(%1)
	adc	a, h
	ld	b,a
} by {
	ld	bc,#%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-297a
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	e,a
	ld	a,#>(%1)
	adc	a, h
	ld	d,a
} by {
	ld	de,#%1
	add	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-297b
} if notUsed('hl')

replace restart {
	ld	de,(#%1)
	ld	hl,#%2
	add	hl,de
	ex	de,hl
} by {
	ld	hl,(#%1)
	ld	de,#%2
	add	hl,de
	ex	de,hl
	; peephole z88dk-298a
} if notUsed('hl')

replace restart {
	ld	de,(#%1)
	ld	hl,#%2
	add	hl,de
} by {
	ld	hl,(#%1)
	ld	de,#%2
	add	hl,de
	; peephole z88dk-298b
} if notUsed('de')

replace restart {
	ld	bc,(#%1)
	ld	hl,#%2
	add	hl,bc
} by {
	ld	hl,(#%1)
	ld	bc,#%2
	add	hl,bc
	; peephole z88dk-298c
} if notUsed('bc')

//replace restart {
//	ld	hl,#%1
//	rl	(hl)
//	inc	hl
//	rl	(hl)
//} by {
//	ld	hl,(#%1)
//	adc	hl,hl
//	ld	(#%1),hl
//	ld	hl,#%1 + 1
//	; peephole z88dk-299a
//}

//replace restart {
//	ld	hl,#%1 + 2
//	rl	(hl)
//	inc	hl
//	rl	(hl)
//} by {
//	ld	hl,(#%1 + 2)
//	adc	hl,hl
//	ld	(#%1 + 2),hl
//	ld	hl,#%1 + 3
//	; peephole z88dk-299b1
//}

//replace restart {
//	ld	hl,#%1 + %2
//	rl	(hl)
//	inc	hl
//	rl	(hl)
//} by {
//	ld	hl,(#%1 + %2)
//	adc	hl,hl
//	ld	(#%1 + %2),hl
//	ld	hl,#%1 + %2+1
//	; peephole z88dk-229b2
//}

replace restart {
%1:
	ld	hl,(#%1)
	add	hl,hl
	ld	(#%1),hl
	ld	hl,(#%1 + 2)
	adc	hl,hl
	ld	(#%1 + 2),hl
	djnz	%1
} by {
	ld	hl,(#%1)
	ld	de,(#%1 + 2)
%1:
	add	hl,hl
	rl	e
	rl	d
	djnz	%1
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ex	de,hl
	; peephole z88dk-299c
} if notUsed('de')

replace restart {
%1:
	ld	hl,(#%1)
	add	hl,hl
	ld	(#%1),hl
	ld	hl,(#%1 + 2)
	adc	hl,hl
	ld	(#%1 + 2),hl
	djnz	%1
} by {
	push	de
	ld	hl,(#%1)
	ld	de,(#%1 + 2)
%1:
	add	hl,hl
	rl	e
	rl	d
	djnz	%1
	ld	(#%1),hl
	ld	(#%1 + 2),de
	ex	de,hl
	pop	de
	; peephole z88dk-299d
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sbc	a, (hl)
	ld	a,(#%1 + 3)
	ld	hl,#%2 + 3
	sbc	a, (hl)
} by {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	a,(#%1 + 1)
	inc	hl
	sbc	a, (hl)
	ld	a,(#%1 + 2)
	inc	hl
	sbc	a, (hl)
	ld	a,(#%1 + 3)
	inc	hl
	sbc	a, (hl)
	; peephole z88dk-300a
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	a,(#%1 + 1)
	ld	hl,#%2 + 1
	sbc	a, (hl)
} by {
	ld	a,(#%1)
	ld	hl,#%2
	sub	a, (hl)
	ld	a,(#%1 + 1)
	inc	hl
	sbc	a, (hl)
	; peephole z88dk-300b
}

replace restart {
	ld	a,(#%3)
	ld	hl,#%4
	sub	a, (hl)
	jp	%1,%2
	ld	a,(#%3 + 1)
	ld	hl,#%4 + 1
	sub	a, (hl)
	jp	%1,%5
	ld	a,(#%3 + 2)
	ld	hl,#%4 + 2
	sub	a, (hl)
	jp	%1,%6
	ld	a,(#%3 + 3)
	ld	hl,#%4 + 3
	sub	a, (hl)
	jp	%8,%7
} by {
	ld	a,(#%3)
	ld	hl,#%4
	sub	a, (hl)
	jp	%1,%2
	ld	a,(#%3 + 1)
	inc	hl
	sub	a, (hl)
	jp	%1,%5
	ld	a,(#%3 + 2)
	inc	hl
	sub	a, (hl)
	jp	%1,%6
	ld	a,(#%3 + 3)
	inc	hl
	sub	a, (hl)
	jp	%8,%7
	; peephole z88dk-301a
}

replace restart {
	ld	a,(#%3)
	ld	hl,#%4
	sub	a, (hl)
	jp	%1,%2
	ld	a,(#%3 + 1)
	ld	hl,#%4 + 1
	sub	a, (hl)
	jp	%6,%5
} by {
	ld	a,(#%3)
	ld	hl,#%4
	sub	a, (hl)
	jp	%1,%2
	ld	a,(#%3 + 1)
	inc	hl
	sub	a, (hl)
	jp	%6,%5
	; peephole z88dk-301b
}

replace restart {
	ld	hl,#%1
	ld	(hl),#0x%2
	xor	a, a
	inc	hl
	ld	(hl),a
	inc	hl
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x00%2
	ld	(#%1),hl
	ld	l,h
	ld	(#%1 + 2),hl
	ld	a,l
	ld	hl,#%1 + 3
	; peephole z88dk-302
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, #0x%2
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a, #0x%3
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	de,#0x%3%2
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-303
}

replace restart {
	push	hl
	dec	hl
	ld	a,(hl)
	ld	(#%1),a
	ld	a,(#%2 + 1)
	ld	(#%1 + 1),a
	pop	hl
} by {
	ld	hl,(#%2)
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-304  Warning may lead to incorrect code
}

replace restart {
	ld	c,l
	ld	b,h
	ld	(%1 + %2),bc
} by {
	ld	(%1 + %2),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-305a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	(%1 + %2 + %3),bc
} by {
	ld	(%1 + %2 + %3),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-305b
}

replace restart {
	ld	e,l
	ld	d,h
	ld	(%1 + %2),de
} by {
	ld	(%1 + %2),hl
	ld	e,l
	ld	d,h
	; peephole z88dk-305c
}

replace restart {
	ld	e,l
	ld	d,h
	ld	(%1 + %2 + %3),de
} by {
	ld	(%1 + %2 + %3),hl
	ld	e,l
	ld	d,h
	; peephole z88dk-305d
}

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-306
} if notUsed('de')

replace restart {
	ld	b,#0x0F
%1:
	sra	%2
	rr	%3
	rr	%4
	rr	%5
	djnz	%1
} by {
	rl	%4
	rl	%3
	rl	%2
	ld	%5,%3
	ld	%4,%2
	sbc	a,a
	ld	%3,a
	ld	%2,a
	ld	b,0
	; peephole z88dk-307
} if notUsed('a')
// labelRefCount

replace restart {
	ex	de,hl
	ld	hl,#%1
	add	hl,de
} by {
	ld	de,#%1
	add	hl,de
	; peephole z88dk-308a
} if notUsed('de')

replace restart {
	ex	de,hl
	ld	hl,#%1 + %2
	add	hl,de
} by {
	ld	de,#%1 + %2
	add	hl,de
	; peephole z88dk-308b
} if notUsed('de')

replace restart {
	ex	de,hl
	ld	hl,#%1
	ex	de,hl
} by {
	ld	de,#%1
	; peephole z88dk-309a
}

replace restart {
	ex	de,hl
	ld	hl,#%1 + %2
	ex	de,hl
} by {
	ld	de,#%1 + %2
	; peephole z88dk-309b
}

replace restart {
	ld	(#%1),hl
	ld	hl,#%1 + 1
	ld	a,(hl)
	dec	hl
	or	a,(hl)
} by {
	ld	(#%1),hl
	ld	a,h
	or	a,l
	ld	hl,#%1
	; peephole z88dk-310a
}
// if notVolatile

replace restart {
	ld	(#%1),hl
	ld	hl,#%1
	ld	a,(hl)
	inc	hl
	or	a,(hl)
} by {
	ld	(#%1),hl
	ld	a,l
	or	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-310b
}
// if notVolatile

//replace restart {
//	ld	bc,#0xFFFF
//	add	hl,bc
//	ex	de,hl
//	ld	bc,#0xFFFF
//	adc	hl,bc
//} by {
//	ex	de,hl
//	ld	a,d
//	or	a,e
//	dec	de
//	jr	NZ,#0x01
//	dec	hl
//	ld	bc,#0xFFFF
//	; peephole z88dk-311a  INCORRECT IF FLAGS USED
//}
// jr is unsafe

replace restart {
	ld	bc,#0xFFFF
	add	hl,bc
	ex	de,hl
	ld	bc,#0xFFFF
	adc	hl,bc
} by {
	ld	bc,#0xFFFF
	add	hl,bc
	ex	de,hl
	adc	hl,bc
	; peephole z88dk-311b
}

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-312a
} if notUsed('de')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	d,l
	ld	e,h
	ld	bc,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-312b
} if notUsed('bc')

replace restart {
	ld	l, e
	ld	h, d
	ld	bc, #%1
	add	hl, bc
} by {
	ld	hl,#%1
	add	hl,de
	; peephole z88dk-313a
} if notUsed('bc')

replace restart {
	ld	l, c
	ld	h, b
	ld	de, #%1
	add	hl, de
} by {
	ld	hl,#%1
	add	hl,bc
	; peephole z88dk-313b
} if notUsed('de')

replace restart {
	ld	b,%3
	ld	a,#<(%1)
	add	a, c
	ld	l,a
	ld	a,#>(%1)
	adc	a, #%2
	ld	h,a
} by {
	ld	b,#%2
	ld	hl,#%1
	add	hl,bc
	ld	a,h
	ld	b,%3
	; peephole z88dk-314a
} if notSame(%3 'a' 'l' 'h')

replace restart {
	ld	d,%3
	ld	a,#<(%1)
	add	a, e
	ld	l,a
	ld	a,#>(%1)
	adc	a, #%2
	ld	h,a
} by {
	ld	d,#%2
	ld	hl,#%1
	add	hl,de
	ld	a,h
	ld	d,%3
	; peephole z88dk-314b
} if notSame(%3 'a' 'l' 'h')

replace restart {
	ld	de,#%1
	ld	bc,#%1
} by {
	ld	de,#%1
	ld	c,e
	ld	b,d
	; peephole z88dk-315a
}

replace restart {
	ld	bc,#%1
	ld	de,#%1
} by {
	ld	bc,#%1
	ld	e,c
	ld	d,b
	; peephole z88dk-315b
}

replace restart {
	ld	hl,#%1
	ld	de,#%1
} by {
	ld	hl,#%1
	ld	e,l
	ld	d,h
	; peephole z88dk-315c
}

replace restart {
	ld	de,#%1
	ld	hl,#%1
} by {
	ld	de,#%1
	ld	l,e
	ld	h,d
	; peephole z88dk-315d
}

replace restart {
	ld	a,e
	add	a,#0x%1
	ld	e,a
	ld	a,d
	adc	a,#0x%2
	ld	d,a
} by {
	ld	hl,#0x%2%1
	add	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-316
} if notUsed('hl')

replace restart {
	ld	b,l
	ld	c,h
	ld	e, b
	ld	d, c
} by {
	ld	b,l
	ld	c,h
	ld	e,l
	ld	d,h
	; peephole z88dk-318a
}

replace restart {
	ld	%1,%2
	or	a,%1
} by {
	ld	%1,%2
	or	a,%2
	; peephole z88dk-318b
} if notSame(%1 'a'), notSame(%2 '(hl)'), notVolatile(%1)


replace restart {
	ld	a,d
	add	a, #0x%1
	ld	b,a
	ld	a,e
	adc	a, #0x%2
	ld	c,a
	ld	l, b
	ld	h, c
} by {
	ld	l,d
	ld	h,e
	ld	bc,#0x%2%1
	add	hl,bc
	ld	a,h
	ld	b,l
	ld	c,h
	; peephole z88dk-319a
}

replace restart {
	ld	d,c
	ld	hl,#%1
	ld	a,(hl)
	add	a, d
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a, b
	ld	(hl),a
} by {
	ld	d,c
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-319b
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	add	hl,bc
} by {
	ld	bc,%1
	add	hl,bc
	; peephole z88dk-319c
} if notUsed('bc')

replace restart {
	ld	e,l
	ld	d,h
	ld	hl,%1
	add	hl,de
} by {
	ld	de,%1
	add	hl,de
	; peephole z88dk-319d
} if notUsed('de')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-320a
} if notUsed('de')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	d,l
	ld	e,h
	ld	bc,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-320b
} if notUsed('bc')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	ld	hl,#%1 + 1
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,e
	inc	hl
	sbc	a, (hl)
	ld	(#%2 + 1),a
	; peephole z88dk-320c
}

replace restart {
	ld	a,#<(%1)
	add	a, %2 (%4)
	ld	d,a
	ld	a,#>(%1)
	adc	a, %3 (%4)
	ld	e,a
	ld	l, d
	ld	h, e
} by {
	ld	l, %2 (%4)
	ld	h, %3 (%4)
	ld	de,#%1
	add	hl,de
	ld	a,h
	ld	d,l
	ld	e,h
	; peephole z88dk-321a
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, #0x%2
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a, #0x%3
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	de,#0x%3%2
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-322a
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, #0x%2
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a, #0x%3
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	bc,#0x%3%2
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-322b
} if notUsed('bc')

replace restart {
	ld	hl,#%1 + 1
	ld	%2,(hl)
	dec	hl
	ld	l, (hl)
	ld	h, %2
} by {
	ld	hl,(#%1)
	ld	%2,h
	; peephole z88dk-323
}

replace restart {
	ld	hl,#%4
	ld	%1,(hl)
	inc	hl
	ld	%2,(hl)
	dec	hl
	ld	%3,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,%3
} by {
	ld	hl,(#%4)
	ld	%1,l
	ld	%2,h
	ld	%3,l
	; peephole z88dk-324
} if notSame(%1 'h' 'l'), notSame(%2 'h' 'l'), notSame(%3 'h' 'l')
// if notVolatile

replace restart {
	ld	%1,(%2)
	ld	%4,%5
	ld	%3,(%2)
} by {
	ld	%1,(%2)
	ld	%4,%5
	ld	%3,%1
	; peephole z88dk-325
} if notSame(%4 %1 %2), operandsNotRelated(%4 %2), canAssign(%3 %1)
// if notVolatile

replace restart {
	ld	hl,#%1 + 1
	ld	a,(de)
	ld	d,a
	rla
	sbc	a, a
	ld	e,a
	ld	b,(hl)
	dec	hl
	ld	c,(hl)
} by {
	ld	a,(de)
	ld	d,a
	rla
	sbc	a, a
	ld	e,a
	ld	bc,(#%1)
	ld	hl,#%1
	; peephole z88dk-326a
}

replace restart {
	ld	de,(#%1)
	ld	hl,#%2 + 1
	ld	a,(de)
	ld	d,a
	dec	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	de,(#%1)
	ld	a,(de)
	ld	d,a
	ld	(#%2),bc
	ld	hl,#%2 + 1
	; peephole z88dk-326b
}

replace restart {
	ld	de,(#%1)
	ld	hl,#%2 + 1
	ld	a,(de)
	ld	%3,a
	dec	hl
} by {
	ld	de,(#%1)
	ld	a,(de)
	ld	%3,a
	ld	hl,#%2
	; peephole z88dk-326c
} if notSame(%3 '(hl)' 'l' 'h')

replace restart {
	ld	(#%1),hl
	ld	hl,#%1 + 1
	bit	%2,(hl)
} by {
	ld	(#%1),hl
	bit	%2,h
	ld	hl,#%1 + 1
	; peephole z88dk-327
}
// if notVolatile

replace restart {
	ld	bc,(#%1)
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	ld	c,l
	ld	b,h
	; peephole z88dk-328a
}

replace restart {
	ld	bc,(#%1)
	inc	bc
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	inc	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-328b
}

replace restart {
	ld	bc,(#%1)
	inc	bc
	inc	bc
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	inc	hl
	inc	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-328c
}

replace restart {
	ld	bc,(#%1)
	inc	bc
	inc	bc
	inc	bc
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	inc	hl
	inc	hl
	inc	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-328d
}

replace restart {
	ld	bc,(#%1)
	inc	bc
	inc	bc
	inc	bc
	inc	bc
	ld	l, c
	ld	h, b
} by {
	ld	hl,(#%1)
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-328e
}

replace restart {
	ld	de,(#%1)
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	ld	e,l
	ld	d,h
	; peephole z88dk-329a
}

replace restart {
	ld	de,(#%1)
	inc	de
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	inc	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-329b
}

replace restart {
	ld	de,(#%1)
	inc	de
	inc	de
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	inc	hl
	inc	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-329c
}

replace restart {
	ld	de,(#%1)
	inc	de
	inc	de
	inc	de
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	inc	hl
	inc	hl
	inc	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-329d
}

replace restart {
	ld	de,(#%1)
	inc	de
	inc	de
	inc	de
	inc	de
	ld	l, e
	ld	h, d
} by {
	ld	hl,(#%1)
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-329e
}

replace restart {
	ld	a,c
	add	a,#0x%2
	ld	hl,#%1
	ld	(hl),a
	ld	a,b
	adc	a,#0x%3
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x%3%2
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-330a
}

replace restart {
	ld	a,e
	add	a,#0x%2
	ld	hl,#%1
	ld	(hl),a
	ld	a,d
	adc	a,#0x%3
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x%3%2
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-330b
}

replace restart {
	ld	%1,l
	ld	%2,h
	ld	%4 (%3),%1
	ld	%5 (%3),%2
	ld	l, %1
	ld	h, %2
} by {
	ld	%1,l
	ld	%2,h
	ld	%4 (%3),l
	ld	%5 (%3),h
	; peephole z88dk-331
}

replace restart {
	ld	%1,(hl)
	ld	%2,%3 
	ld	l, %1
	ld	h, %2
} by {
	ld	l,(hl)
	ld	h,%3
	ld	%1,l
	ld	%2,h
	; peephole z88dk-332
} if notSame(%3 '(hl)' 'l' 'h' %1), notSame(%2 '(hl)' 'l' 'h' %1)
// if notVolatile

replace restart {
	ld	%1,%2
	ld	%3,%4
	ld	%2,%1
} by {
	ld	%1,%2
	ld	%3,%4
	; peephole z88dk-333
} if notSame(%3 %1 %2), notSame(%4 %1 %2), operandsNotRelated(%2 %3), operandsNotRelated(%1 %3)
// if notVolatile

replace restart {
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sub	a, (hl)
	jp	%3,%4
	ld	a,(#%1 + 3)
	ld	hl,#%2 + 3
	sub	a, (hl)
} by {
	ld	a,(#%1 + 2)
	ld	hl,#%2 + 2
	sub	a, (hl)
	jp	%3,%4
	ld	a,(#%1 + 3)
	inc	hl
	sub	a, (hl)
	; peephole z88dk-334
}

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3 + %4)
	ld	(#%5 + %6),hl
	pop	hl
} by {
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3 + %4)
	ld	(#%5 + %6),hl
	; peephole z88dk-335a
} if notUsed('hl')

replace restart {
	push	hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3 + %4)
	ld	(#%5 + %6),hl
	pop	hl
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	(#%2),hl
	ld	hl,(#%3 + %4)
	ld	(#%5 + %6),hl
	ex	de,hl
	; peephole z88dk-335b
} if notUsed('de')

replace restart {
	ld	%1, a
	%2	%1
	ld	a,%3 (%4)
	add	a, %1
} by {
	%2	a
	add	a,%3 (%4)
	; peephole z88dk-336
} if notSame(%1 '(hl)'), notUsed(%1)

replace restart {
	ld	a,%1 (%2)
	or	a, a
	jp	%3,%4
	ld	a,%1 (%2)
} by {
	ld	a,%1 (%2)
	or	a, a
	jp	%3,%4
	; peephole z88dk-337a
}
// if notVolatile

replace restart {
	ld	a,%1
	or	a, a
	jp	%3,%4
	ld	a,%1
} by {
	ld	a,%1
	or	a, a
	jp	%3,%4
	; peephole z88dk-337b
}
// if notVolatile

replace restart {
	ld	c,l
	ld	b,h
	ld	a,(de)
	ld	(bc),a
} by {
	ld	a,(de)
	ld	(hl),a
	ld	c,l
	ld	b,h
	; peephole z88dk-338
}

replace restart {
	ld	hl,#%1
	ld	%3,%4
} by {
	ld	%3,%4
	ld	hl,#%1
	; peephole z88dk-339a
} if operandsNotRelated(%3 'hl'), operandsNotRelated(%4 'hl')

replace restart {
	ld	hl,#%1 + %2
	ld	%3,%4
} by {
	ld	%3,%4
	ld	hl,#%1 + %2
	; peephole z88dk-339b
} if operandsNotRelated(%3 'hl'), operandsNotRelated(%4 'hl')

replace restart {
	ld	hl,#%1
	xor	a,%3
} by {
	xor	a,%3
	ld	hl,#%1
	; peephole z88dk-339c
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%1 + %4
	xor	a,%3
} by {
	xor	a,%3
	ld	hl,#%1 + %4
	; peephole z88dk-339d
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%1
	inc	%3
} by {
	inc	%3
	ld	hl,#%1
	; peephole z88dk-339e
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%1
	dec	%3
} by {
	dec	%3
	ld	hl,#%1
	; peephole z88dk-339f
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%1 + %2
	inc	%3
} by {
	inc	%3
	ld	hl,#%1 + %2
	; peephole z88dk-339g
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%1 + %2
	dec	%3
} by {
	dec	%3
	ld	hl,#%1 + %2
	; peephole z88dk-339h
} if operandsNotRelated(%3 'hl')

replace restart {
	ex	de,hl
	xor	a,a
} by {
	xor	a,a
	ex	de,hl
	; peephole z88dk-340a
}

replace restart {
	ex	de,hl
	ld	(de),a
} by {
	ld	(hl),a
	ex	de,hl
	; peephole z88dk-340b
}

replace restart {
	ex	de,hl
	inc	%1
} by {
	inc	%1
	ex	de,hl
	; peephole z88dk-340c
} if notSame(%1 'd' 'e' 'h' 'l' 'de' 'hl' '(hl)')

replace restart {
	ex	de,hl
	dec	%1
} by {
	dec	%1
	ex	de,hl
	; peephole z88dk-340d
} if notSame(%1 'd' 'e' 'h' 'l' 'de' 'hl' '(hl)')

replace restart {
	ld	%1,h
	ex	de,hl
} by {
	ex	de,hl
	ld	%1,d
	; peephole z88dk-340e
} if notSame(%1 'l' 'h' 'e' 'd')

replace restart {
	ld	%1,l
	ex	de,hl
} by {
	ex	de,hl
	ld	%1,e
	; peephole z88dk-340f
} if notSame(%1 'l' 'h' 'e' 'd')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	e,a
	ld	a,#>(%1)
	adc	a, #%3
	ld	d,a
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	de,#%1
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%2
	; peephole z88dk-341a
}

replace restart {
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
} by {
	ld	%2,%3
	ld	%4,%5
	; peephole z88dk-342a
} if operandsNotRelated(%2 %1), operandsNotRelated(%4 %1), notSame(%1 'af')

replace restart {
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
} by {
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	; peephole z88dk-342b
} if operandsNotRelated(%2 %6), operandsNotRelated(%4 %6), notSame(%6 'af')

replace restart {
	push	%7
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
	pop	%7
} by {
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
	; peephole z88dk-342c
} if operandsNotRelated(%2 %7), operandsNotRelated(%4 %7), notSame(%7 'af')

replace restart {
	push	%8
	push	%7
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
	pop	%7
	pop	%8
} by {
	push	%7
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
	pop	%7
	; peephole z88dk-342d
} if operandsNotRelated(%2 %8), operandsNotRelated(%4 %8), notSame(%8 'af')

replace restart {
	push	%9
	push	%8
	push	%7
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
	pop	%7
	pop	%8
	pop	%9
} by {
	push	%8
	push	%7
	push	%6
	push	%1
	ld	%2,%3
	ld	%4,%5
	pop	%1
	pop	%6
	pop	%7
	pop	%8
	; peephole z88dk-342e
} if operandsNotRelated(%2 %9), operandsNotRelated(%4 %9), notSame(%9 'af')

replace restart {
	ld	b,l
	ld	c,h
	ld	a,e
	add	a, b
	ld	e,a
	ld	a,d
	adc	a, c
	ld	d,a
} by {
	ld	b,l
	ld	c,h
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	l,b
	ld	h,c
	; peephole z88dk-343
}

replace restart {
	ld	hl,#%1
	ld	l,(hl)
} by {
	ld	hl,(#%1)
	ld	h,#>(%1)
	; peephole z88dk-344
}

replace restart {
	ld	%1,#>(%2)
} by {
	; peephole z88dk-345a
} if notUsed(%1), notSame(%1 '(hl)')

replace restart {
	ld	%1,#<(%2)
} by {
	; peephole z88dk-345b
} if notUsed(%1), notSame(%1 '(hl)')

replace restart {
	ld	d,l
	ld	e,h
	ld	bc,%1
	ld	l, d
	ld	h, e
} by {
	ld	d,l
	ld	e,h
	ld	bc,%1
	; peephole z88dk-346a
}

replace restart {
	ld	d,l
	ld	e,h
	pop	%1
	ld	a,e
	or	a,d
} by {
	ld	d,l
	ld	e,h
	pop	%1
	ld	a,h
	or	a,l
	; peephole z88dk-346b
} if notSame(%1 'hl' 'de')

replace restart {
	ld	c,l
	ld	b,h
	ld	%1,(#%2)
	push	bc
} by {
	ld	%1,(#%2)
	push	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-346c
} if notSame(%1 'bc' 'hl')

replace restart {
	ld	a,%1 (%2)
	ld	hl,#%4
	add	a, (hl)
	ld	e,a
	ld	a,%3 (%2)
	inc	hl
	adc	a, (hl)
	ld	d,a
} by {
	ld	e,%1 (%2)
	ld	d,%3 (%2)
	ld	hl,(#%4)
	add	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%4 + 1
	; peephole z88dk-347a
}

replace restart {
	ld	hl,#%4
	ld	d,(hl)
	inc	hl
	ld	e,(hl)
	ld	a,d
	add	a, %1 (%2)
	dec	hl
	ld	(hl),a
	ld	a,e
	adc	a, %3 (%2)
	inc	hl
	ld	(hl),a
} by {
	ld	hl,(#%4)
	ld	e,%1 (%2)
	ld	d,%3 (%2)
	add	hl,de
	ld	a,h
	ld	(#%4),hl
	ld	hl,#%4 + 1
	; peephole z88dk-347b
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	b,(hl)
	inc	hl
	ld	c,(hl)
	ld	a,b
	add	a, e
	dec	hl
	ld	(hl),a
	ld	a,c
	adc	a, d
	inc	hl
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	b,l
	ld	c,h
	add	hl,de
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-347c
}

replace restart {
	ld	hl,(#%1)
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%2
	add	a, (hl)
	ld	(#%1),a
	ld	a,e
	ld	hl,#%2 + 1
	adc	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	de,(#%1)
	ld	hl,(#%2)
	add	hl,de
	ld	a,d
	ld	d,e
	ld	e,a
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-347d
}

replace restart {
	ld	%1,%6
	ld	%2,%7
	ld	%3 (%5),%1
	ld	%4 (%5),%2
} by {
	ld	%1,%6
	ld	%2,%7
	ld	%3 (%5),%6
	ld	%4 (%5),%7
	; peephole z88dk-348a
} if canAssign(%3 %5 %6), canAssign(%4 %5 %7), operandsNotRelated(%2 %6), operandsNotRelated(%2 %1)

replace restart {
	ld	%1,%3 (%5)
	ld	%2,%4 (%5)
	ld	l, %1
	ld	h, %2
} by {
	ld	l,%3 (%5)
	ld	h,%4 (%5)
	ld	%1,l
	ld	%2,h
	; peephole z88dk-348b
} if notSame(%1 %2), operandsNotRelated(%1 'hl'), operandsNotRelated(%2 'hl')

replace restart {
	ld	b,#0x10
	ld	hl,#%1
%2:
	srl	h
	rr	l
	rr	%3
	rr	%4
	djnz	%2
} by {
	ld	%3,h
	ld	%4,l
	ld	l,#0x00
	ld	h,l
	ld	b,l
	; peephole z88dk-349a
}

replace restart {
	ld	b,#0x10
%1:
	srl	d
	rr	e
	rr	h
	rr	l
	djnz	%1
} by {
	ex	de,hl
	ld	e,#0x00
	ld	d,e
	ld	b,e
	; peephole z88dk-349b
}

replace restart {
	pop	de
	ld	l, e
	ld	h, d
} by {
	pop	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-350a
}

replace restart {
	pop	bc
	ld	l, c
	ld	h, b
} by {
	pop	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-350b
}

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	ld	(#%1 + %2),de
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-351a
}

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	(#%1 + %2),bc
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-351b
}

replace restart {
	ld	c,l
	ld	b,h
	ld	(#%1),bc
} by {
	ld	(#%1),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-352
}

replace restart {
	ld	b,l
	ld	c,h
	ld	a,b
	add	a,#0x%1
	ld	l,a
	ld	a,c
	adc	a,#0x%2
	ld	h,a
} by {
	ld	bc,#0x%2%1
	add	hl,bc
	ld	a,h
	; peephole z88dk-353a
} if notUsed('bc')

replace restart {
	ld	a,e
	adc	a,#0x%1
	ld	e,a
	ld	a,d
	adc	a,#0x%2
	ld	d,a
} by {
	ld	hl,#0x%2%1
	adc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-353b
} if notUsed('hl')

replace restart {
	ld	a,e
	adc	a,#0x%1
	ld	e,a
	ld	a,d
	adc	a,#0x%2
	ld	d,a
} by {
	ex	de,hl
	ld	bc,#0x%2%1
	adc	hl,bc
	ld	a,h
	ex	de,hl
	; peephole z88dk-353c
} if notUsed('bc')

replace restart {
	ld	d,l
	ld	e,h
	ld	a,d
	ld	hl,#%1
	sub	a, (hl)
	ld	d,a
	ld	a,e
	inc	hl
	sbc	a, (hl)
	ld	e,a
} by {
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	d,l
	ld	e,h
	ld	hl,#%1 + 1
	; peephole z88dk-354a
}

replace restart {
	ld	d,l
	ld	e,h
	ld	hl,#%1
	ld	a,(hl)
	sub	a, d
	inc	hl
	ld	a,(hl)
	sbc	a, e
} by {
	ex	de,hl
	ld	hl,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-354b
} if notUsed('de')

replace restart {
	push	af
	ld	%1 (%5),%6
	ld	%2 (%5),%7
	ld	%3 (%5),%8
	ld	%4 (%5),%9
	pop	af
} by {
	ld	%1 (%5),%6
	ld	%2 (%5),%7
	ld	%3 (%5),%8
	ld	%4 (%5),%9
	; peephole z88dk-355a
}

replace restart {
	push	af
	ld	%1 (%5),%6
	ld	%2 (%5),%7
	pop	af
} by {
	ld	%1 (%5),%6
	ld	%2 (%5),%7
	; peephole z88dk-355b
}

replace restart {
	push	%1
	ld	%2,%3
	pop	%1
} by {
	ld	%2,%3
	; peephole z88dk-356
} if operandsNotRelated(%1 %2)

replace restart {
	ld	%3,#%1
	ld	a,%2 (%3)
} by {
	ld	a,(#%1 + %2)
	ld	%3,#%1
	; peephole z88dk-357a
} 

replace restart {
	ld	%3,#%1
	ld	%4,%2 (%3)
} by {
	ld	a,(#%1 + %2)
	ld	%4,a
	ld	%3,#%1
	; peephole z88dk-357b
} if notSame(%4 'a'), notUsed('a')

replace restart {
	ld	%1,%3 (%4)
	ld	%2,%1
} by {
	ld	%2,%3 (%4)
	; peephole z88dk-358
} if notUsed(%1), canAssign(%2 %3 %4)

replace restart {
	ex	de,hl
	ld	hl,#%1
	add	hl,de
} by {
	ld	de,#%1
	add	hl,de
	; peephole z88dk-359
} if notUsed('de')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	b,a
	ld	a,#>(%1)
	inc	hl
	adc	a, (hl)
	ld	c,a
} by {
	ld	bc,#%1
	ld	hl,(#%2)
	add	hl,bc
	ld	a,h
	ld	b,l
	ld	c,h
	ld	hl,#%2 + 1
	; peephole z88dk-360
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, e
	ld	e,a
	inc	hl
	ld	a,(hl)
	sbc	a, d
	ld	d,a
} by {
	ld	hl,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-361
}

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	%2 (%4),a
	ld	a,#>(%1)
	adc	a, h
	ld	%3 (%4),a
} by {
	ld	bc,#%1
	add	hl,bc
	ld	%2 (%4),l
	ld	%3 (%4),h
	ld	a,h
	; peephole z88dk-362a
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a, l
	ld	%2 (%4),a
	ld	a,#>(%1)
	adc	a, h
	ld	%3 (%4),a
} by {
	ld	de,#%1
	add	hl,de
	ld	%2 (%4),l
	ld	%3 (%4),h
	ld	a,h
	; peephole z88dk-362b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	a,e
	add	a,#0xFF
	ld	%1 (%3),a
	ld	a,d
	adc	a,#0xFF
	ld	%2 (%3),a
} by {
	dec	de
	ld	%1 (%3),e
	ld	%2 (%3),d
	ld	a,d
	inc	de
	; peephole z88dk-363a
}

replace restart {
	ld	a,c
	add	a,#0xFF
	ld	%1 (%3),a
	ld	a,b
	adc	a,#0xFF
	ld	%2 (%3),a
} by {
	dec	bc
	ld	%1 (%3),c
	ld	%2 (%3),b
	ld	a,b
	inc	bc
	; peephole z88dk-363b
}

replace restart {
	ld	a,l
	add	a,#0xFF
	ld	%1 (%3),a
	ld	a,h
	adc	a,#0xFF
	ld	%2 (%3),a
} by {
	dec	hl
	ld	%1 (%3),l
	ld	%2 (%3),h
	ld	a,h
	inc	hl
	; peephole z88dk-363c
}

replace restart {
	ld	%1,%2 (%3)
	bit	%4, %2 (%3)
} by {
	ld	%1,%2 (%3)
	bit	%4,%1
	; peephole z88dk-364a
}
// if notVolatile

replace restart {
	ld	%1,%2 (%3)
	set	%4, %2 (%3)
} by {
	ld	%1,%2 (%3)
	set	%4,%1
	; peephole z88dk-364b
}
// if notVolatile

replace restart {
	ld	%1,%2 (%3)
	res	%4, %2 (%3)
} by {
	ld	%1,%2 (%3)
	res	%4,%1
	; peephole z88dk-364c
}
// if notVolatile

replace restart {
	ld	%3 (%4), %1
	ld	%2, %1
	ld	%3 (%4), %2
} by {
	ld	%3 (%4), %1
	ld	%2, %1
	; peephole z88dk-365
}
// if notVolatile

replace restart {
	ld	%1,#%2
} by {
	; peephole z88dk-366
} if notUsed(%1), notVolatile(%1)

replace restart {
	ld	a,(#%1)
	ld	l,a
} by {
	ld	hl,(#%1)
	; peephole z88dk-367
} if notUsed('h'), notUsed('a')

replace restart {
	ld	%1,#%2
	sla	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	sla	%4 (%1)
	; peephole z88dk-368a
}

replace restart {
	ld	%1,#%2
	sra	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	sra	%4 (%1)
	; peephole z88dk-368b
}

replace restart {
	ld	%1,#%2
	rl	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	rl	%4 (%1)
	; peephole z88dk-368c
}

replace restart {
	ld	%1,#%2
	rr	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	rr	%4 (%1)
	; peephole z88dk-368d
}

replace restart {
	ld	%1,#%2
	srl	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	srl	%4 (%1)
	; peephole z88dk-368e
}

replace restart {
	ld	%1,#%2
	rrc	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	rrc	%4 (%1)
	; peephole z88dk-368f
}

replace restart {
	ld	%1,#%2
	rlc	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	rlc	%4 (%1)
	; peephole z88dk-368g
}

replace restart {
	ld	%1,#%2
	inc	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	inc	%4 (%1)
	; peephole z88dk-368h
}

replace restart {
	ld	%1,#%2
	dec	%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	dec	%4 (%1)
	; peephole z88dk-368i
}

replace restart {
	ld	%1,#%2
	ld	%3,%4 (%1)
	ld	%1,#%2
} by {
	ld	%1,#%2
	ld	%3,%4 (%1)
	; peephole z88dk-368y
}

replace restart {
	ld	%1,#%2
	ld	%4 (%1),%3
	ld	%1,#%2
} by {
	ld	%1,#%2
	ld	%4 (%1),%3
	; peephole z88dk-368z
}

replace restart {
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
	inc	(hl)
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
} by {
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
	inc	(hl)
	; peephole z88dk-369a
}
// flags

replace restart {
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
	dec	(hl)
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
} by {
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
	dec	(hl)
	; peephole z88dk-369b
}
// flags

replace restart {
	ld	hl,#%1 + %2
	ld	b,(hl)
	dec	hl
	ld	c,(hl)
} by {
	ld	bc,(#%1 + %2 - 1)
	ld	hl,#%1 + %2 - 1
	; peephole z88dk-370a
}

replace restart {
	ld	hl,#%1 + %2
	ld	d,(hl)
	dec	hl
	ld	e,(hl)
} by {
	ld	de,(#%1 + %2 - 1)
	ld	hl,#%1 + %2 - 1
	; peephole z88dk-370b
}

replace restart {
	ld	a,%1
	cp	a,a
} by {
	xor	a,a
	ld	a,%1
	; peephole z88dk-371
}

replace restart {
	ld	h,%1
	ld	l,%2
	ld	a,e
	sub	a, h
	ld	e,a
	ld	a,d
	sbc	a, l
	ld	d,a
} by {
	ld	l,%1
	ld	h,%2
	ex	de,hl
	xor	a,a
	sbc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-372a
}

replace restart {
	ld	b,l
	ld	c,h
	ld	a,e
	sub	a, b
	ld	e,a
	ld	a,d
	sbc	a, c
	ld	d,a
} by {
	ld	b,l
	ld	c,h
	ex	de,hl
	xor	a,a
	sbc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-372b
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, c
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a, b
	ld	b,a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-373a
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	d,a
	ld	a,#>(%1)
	inc	hl
	adc	a, (hl)
	ld	l,d
	ld	h,a
} by {
	ld	hl,(#%2)
	ld	de,#%1
	add	hl,de
	ld	d,l
	ld	a,h
	; peephole z88dk-373b
} if notUsed('e')

replace restart {
	ld	de,(#%1)
	ld	a,(de)
} by {
	ld	hl,(#%1)
	ld	a,(hl)
	; peephole z88dk-374a
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	bc,(#%1)
	ld	a,(bc)
} by {
	ld	hl,(#%1)
	ld	a,(hl)
	; peephole z88dk-374b
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	bc,#%1
	ld	l,c
	ld	h,b
} by {
	ld	hl,#%1
	; peephole z88dk-375a
} if notUsed('bc')

replace restart {
	push	%13
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	%7,%8 (%9)
	ld	%10,%11 (%12)
	pop	%13
} by {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	%7,%8 (%9)
	ld	%10,%11 (%12)
	; peephole z88dk-376a
} if operandsNotRelated(%13 %1), operandsNotRelated(%13 %4), operandsNotRelated(%13 %7), operandsNotRelated(%13 %10)

replace restart {
	push	%13
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	pop	%13
} by {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	; peephole z88dk-376b
} if operandsNotRelated(%13 %1), operandsNotRelated(%13 %4)

replace restart {
	ld	%5,%6
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%7,%5
} by {
	ld	%5,%6
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%7,%6
	; peephole z88dk-376c
} if notVolatile(%5), canAssign(%6 '(hl)'), canAssign(%7 '(hl)')

replace restart {
	ld	hl,#%1 + 2
	sbc	a, (hl)
	ld	e,a
	ld	a,(#%2 + %3)
	ld	hl,#%1 + 3
} by {
	ld	hl,#%1 + 2
	sbc	a, (hl)
	ld	e,a
	ld	a,(#%2 + %3)
	inc	hl
	; peephole z88dk-377a
}

replace restart {
	ld	bc,(%1)
	ld	(%2),bc
} by {
	ld	hl,(%1)
	ld	(%2),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-378a
} if notUsed('hl')

replace restart {
	ld	de,(%1)
	ld	(%2),de
} by {
	ld	hl,(%1)
	ld	(%2),hl
	ld	e,l
	ld	d,h
	; peephole z88dk-378b
} if notUsed('hl')

replace restart {
	ld	de,#%1
	ld	hl,#%2
	ldi
	ld	a,(hl)
	ld	(de),a
} by {
	ld	hl,(#%2)
	ld	(#%1),hl
	dec	bc
	ld	a,h
	ld	de,#%1 + 1
	ld	hl,#%2 + 1
	; peephole z88dk-379a
}

replace restart {
	ld	de,#%1
	ld	hl,#%2
	ldi
	inc	bc
	ld	a,(hl)
	ld	(de),a
} by {
	ld	hl,(#%2)
	ld	(#%1),hl
	ld	a,h
	ld	de,#%1 + 1
	ld	hl,#%2 + 1
	; peephole z88dk-379b
}

replace restart {
	ld	bc,%1
	ld	hl,%2
	ld	a,(hl)
	ld	(bc),a
	inc	bc
	inc	hl
	ld	a,(hl)
	ld	(bc),a
} by {
	ld	de,%1
	ld	hl,%2
	ldi
	ld	a,(hl)
	ld	(de),a
	ld	c,e
	ld	b,d
	; peephole z88dk-379c
} if notUsed('de')

replace restart {
	ld	a,c
	ld	hl,%1
	add	a, (hl)
	ld	(%2),a
	ld	a,b
	ld	hl,%1 + 1
	adc	a, (hl)
	ld	(%2 + 1),a
	ld	a,e
	ld	hl,%1 + 2
	adc	a, (hl)
	ld	(%2 + 2),a
	ld	a,d
	ld	hl,%1 + 3
	adc	a, (hl)
	ld	(%2 + 3),a
} by {
	ld	hl,(%1)
	add	hl,bc
	ld	(%2),hl
	ld	hl,(%1 + 2)
	adc	hl,de
	ld	(%2 + 2),hl
	ld	a,h
	ld	hl,%1 + 3
	; peephole z88dk-380a
}

replace restart {
	inc	de
} by {
	; peephole z88dk-381b removed dead increment of de.
} if notUsed('de')

replace restart {
	inc	bc
} by {
	; peephole z88dk-381c removed dead increment of bc.
} if notUsed('bc')

//replace restart {
//	inc	ix
//} by {
//	; peephole z88dk-381d removed dead increment of ix.
//} if notUsed('ix')

//replace restart {
//	inc	iy
//} by {
//	; peephole z88dk-381e removed dead increment of iy.
//} if notUsed('iy')

replace restart {
	dec	de
} by {
	; peephole z88dk-382b removed dead decrement of de.
} if notUsed('de')

replace restart {
	dec	bc
} by {
	; peephole z88dk-382c removed dead decrement of bc.
} if notUsed('bc')

//replace restart {
//	dec	ix
//} by {
//	; peephole z88dk-382d removed dead decrement of ix.
//} if notUsed('ix')

//replace restart {
//	dec	iy
//} by {
//	; peephole z88dk-382e removed dead decrement of iy.
//} if notUsed('iy')

replace restart {
	ld	%2,%3
	ld	hl,%1
	ld	(hl),%2
} by {
	ld	hl,%1
	ld	(hl),%3
	; peephole z88dk-383a
} if canAssign('(hl)' %3), notUsed(%2), operandsNotRelated(%3 'hl'), operandsNotRelated(%2 'hl')

replace restart {
	ld	%2,%3
	ld	hl,#%1
	ld	(hl),%2
} by {
	ld	a,%3
	ld	(#%1),a
	ld	%2,a
	; peephole z88dk-383b
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	%1,%2
	dec	%1
	ld	a,%1
	ld	%2,%1
} by {
	dec	%2
	ld	%1,%2
	ld	a,%2
	; peephole z88dk-384
} if notSame(%2 '(hl)'), notSame(%2 '(de)'), notSame(%2 '(bc)')

replace restart {
	ld	hl,#%1
	ld	%2,(hl)
	ld	a,%2
} by {
	ld	a,(#%1)
	ld	%2,a
	; peephole z88dk-385
} if notUsed('hl')

replace restart {
	ld	%1,%2
	bit	%3,%1
} by {
	ld	%1,%2
	bit	%3,%2
	; peephole z88dk-386a
} if notVolatile(%1), canAssign(%2 '(hl)')

replace restart {
	ld	%1,%2
	ld	%4,%5
	bit	%3,%1
} by {
	bit	%3,%2
	ld	%1,%2
	ld	%4,%5
	; peephole z88dk-386b
} if same(%2 'a' 'b' 'c' 'd' 'e' 'h' 'l'), operandsNotRelated(%4 %1), notVolatile(%1)

replace restart {
	ld	%2,#0
	add	%2,sp
	push	%3
	ld	-2 (%2),#<(%1)
	ld	-1 (%2),#>(%1)
} by {
	ld	%2,#0
	add	%2,sp
	ld	bc,#%1
	push	bc
	; peephole z88dk-387a
} if notUsed('bc')

replace restart {
	ld	%2,#0
	add	%2,sp
	push	%3
	ld	-2 (%2),#<(%1)
	ld	-1 (%2),#>(%1)
} by {
	ld	%2,#0
	add	%2,sp
	ld	hl,#%1
	push	hl
	; peephole z88dk-387b
} if notUsed('hl')

replace restart {
	call	___sdcc_enter_ix
	push	%3
	ld	-2 (ix),#<(%1)
	ld	-1 (ix),#>(%1)
} by {
	call	___sdcc_enter_ix
	ld	bc,#%1
	push	bc
	; peephole z88dk-387c
} if notUsed('bc')

replace restart {
	call	___sdcc_enter_ix
	push	%3
	ld	-2 (ix),#<(%1)
	ld	-1 (ix),#>(%1)
} by {
	call	___sdcc_enter_ix
	ld	hl,#%1
	push	hl
	; peephole z88dk-387d
} if notUsed('hl')

replace restart {
	ld	%2,#0
	add	%2,sp
	push	af
	ld	a,%4 (%3)
	ld	-2 (%2),a
	ld	a,%5 (%3)
	ld	-1 (%2),a
} by {
	ld	%2,#0
	add	%2,sp
	ld	l,%4 (%3)
	ld	h,%5 (%3)
	ld	a,h
	push	hl
	; peephole z88dk-387e
} if notUsed('hl')

replace restart {
	ld	%2,#0
	add	%2,sp
	push	af
	ld	a,%4 (%3)
	ld	-2 (%2),a
	ld	a,%5 (%3)
	ld	-1 (%2),a
} by {
	ld	%2,#0
	add	%2,sp
	ld	c,%4 (%3)
	ld	b,%5 (%3)
	ld	a,b
	push	bc
	; peephole z88dk-387f
} if notUsed('bc')

replace restart {
	call	___sdcc_enter_ix
	push	af
	ld	a,%4 (%3)
	ld	-2 (ix),a
	ld	a,%5 (%3)
	ld	-1 (ix),a
} by {
	call	___sdcc_enter_ix
	ld	l,%4 (%3)
	ld	h,%5 (%3)
	ld	a,h
	push	hl
	; peephole z88dk-387g
} if notUsed('hl')

replace restart {
	call	___sdcc_enter_ix
	push	af
	ld	a,%4 (%3)
	ld	-2 (ix),a
	ld	a,%5 (%3)
	ld	-1 (ix),a
} by {
	call	___sdcc_enter_ix
	ld	c,%4 (%3)
	ld	b,%5 (%3)
	ld	a,b
	push	bc
	; peephole z88dk-387h
} if notUsed('bc')

replace restart {
	ld	%2,#0
	add	%2,sp
	push	af
	push	af
	ld	-4 (%2),#<(%1)
	ld	-3 (%2),#>(%1)
} by {
	ld	%2,#0
	add	%2,sp
	push	af
	ld	bc,#%1
	push	bc
	; peephole z88dk-387i
} if notUsed('bc')

replace restart {
	ld	%2,#0
	add	%2,sp
	push	af
	push	af
	ld	-4 (%2),#<(%1)
	ld	-3 (%2),#>(%1)
} by {
	ld	%2,#0
	add	%2,sp
	push	af
	ld	hl,#%1
	push	hl
	; peephole z88dk-387j
} if notUsed('hl')

replace restart {
	call	___sdcc_enter_ix
	push	af
	push	af
	ld	-4 (ix),#<(%1)
	ld	-3 (ix),#>(%1)
} by {
	call	___sdcc_enter_ix
	push	af
	ld	bc,#%1
	push	bc
	; peephole z88dk-387k
} if notUsed('bc')

replace restart {
	call	___sdcc_enter_ix
	push	af
	push	af
	ld	-4 (ix),#<(%1)
	ld	-3 (ix),#>(%1)
} by {
	call	___sdcc_enter_ix
	push	af
	ld	hl,#%1
	push	hl
	; peephole z88dk-387l
} if notUsed('hl')

replace restart {
	ld	%2,#0
	add	%2,sp
	push	af
	dec	sp
	ld	-3 (%2),#%1
} by {
	ld	%2,#0
	add	%2,sp
	push	af
	ld	a,#%1
	push	af
	inc	sp
	; peephole z88dk-387m
} if notUsed('a')

replace restart {
	call	___sdcc_enter_ix
	push	af
	dec	sp
	ld	-3 (ix),#%1
} by {
	call	___sdcc_enter_ix
	push	af
	ld	a,#%1
	push	af
	inc	sp
	; peephole z88dk-387n
} if notUsed('a')

replace restart {
	call	___sdcc_enter_ix
	push	af
	push	af
	ld	-2 (ix),#0x%1
	ld	-1 (ix),#0x%2
	ld	hl,%5
	ex	(sp),hl
} by {
	call	___sdcc_enter_ix
	ld	hl,#0x%2%1
	push	hl
	ld	hl,%5
	push	hl
	; peephole z88dk-387o1
}

replace restart {
	call	___sdcc_enter_ix
	push	af
	push	af
	ld	-2 (ix),#0x%1
	ld	-1 (ix),#0x%2
} by {
	call	___sdcc_enter_ix
	ld	bc,#0x%2%1
	push	bc
	push	af
	; peephole z88dk-387o2
} if notUsed('bc')

replace restart {
	call	___sdcc_enter_ix
	push	af
	push	af
	ld	-2 (ix),#0x%1
	ld	-1 (ix),#0x%2
} by {
	call	___sdcc_enter_ix
	ld	hl,#0x%2%1
	push	hl
	push	af
	; peephole z88dk-387p
} if notUsed('hl')

replace restart {
	ld	%4,#0
	add	%4,sp
	push	af
	push	af
	ld	-2 (%4),#0x%1
	ld	-1 (%4),#0x%2
	ld	hl,%5
	ex	(sp),hl
} by {
	ld	%4,#0
	add	%4,sp
	ld	hl,#0x%2%1
	push	hl
	ld	hl,%5
	push	hl
	; peephole z88dk-387q1
}

replace restart {
	ld	%4,#0
	add	%4,sp
	push	af
	push	af
	ld	-2 (%4),#0x%1
	ld	-1 (%4),#0x%2
} by {
	ld	%4,#0
	add	%4,sp
	ld	bc,#0x%2%1
	push	bc
	push	af
	; peephole z88dk-387q2
} if notUsed('bc')

replace restart {
	ld	%4,#0
	add	%4,sp
	push	af
	push	af
	ld	-2 (%4),#0x%1
	ld	-1 (%4),#0x%2
} by {
	ld	%4,#0
	add	%4,sp
	ld	hl,#0x%2%1
	push	hl
	push	af
	; peephole z88dk-387r
} if notUsed('hl')

replace restart {
	ld	l, c
	ld	h, b
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ld	l, c
	ld	h, b
} by {
	ld	l,c
	ld	h,b
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	dec	hl
	; peephole z88dk-388
}

replace restart {
	push	bc
	pop	de
} by {
	ld	e,c
	ld	d,b
	; peephole z88dk-389a
}

replace restart {
	push	de
	pop	bc
} by {
	ld	c,e
	ld	b,d
	; peephole z88dk-389b
}

replace restart {
	push	bc
	pop	hl
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-389c
}

replace restart {
	push	hl
	pop	bc
} by {
	ld	c,l
	ld	b,h
	; peephole z88dk-389d
}

replace restart {
	push	hl
	pop	de
} by {
	ld	e,l
	ld	d,h
	; peephole z88dk-389e
}

replace restart {
	push	de
	pop	hl
} by {
	ld	l,e
	ld	h,d
	; peephole z88dk-389f
}

replace restart {
	ld	a,%1
	ld	(%2),a
	inc	%3
	ld	a,%1
} by {
	ld	a,%1
	ld	(%2),a
	inc	%3
	; peephole z88dk-390
} if operandsNotRelated(%1 %3), operandsNotRelated(%3 'a')

replace restart {
	ld	b,a
	push	bc
	inc	sp
} by {
	ld	b,a
	push	af
	inc	sp
	; peephole z88dk-391a
}

replace restart {
	ld	d,a
	push	de
	inc	sp
} by {
	ld	d,a
	push	af
	inc	sp
	; peephole z88dk-391b
}

replace restart {
	ld	h,a
	push	hl
	inc	sp
} by {
	ld	h,a
	push	af
	inc	sp
	; peephole z88dk-391c
}

replace restart {
	ld	e,%1
	push	de
	inc	sp
} by {
	push	de
	inc	sp
	ld	e,%1
	; peephole z88dk-392a
}

replace restart {
	ld	c,%1
	push	bc
	inc	sp
} by {
	push	bc
	inc	sp
	ld	c,%1
	; peephole z88dk-392b
}

replace restart {
	ld	l,%1
	push	hl
	inc	sp
} by {
	push	hl
	inc	sp
	ld	l,%1
	; peephole z88dk-392c
}

replace restart {
	ld	a,c
	add	a,#0x%1
	ld	e,a
	ld	a,b
	adc	a,#0x%2
	ld	d,a
} by {
	ld	hl,#0x%2%1
	add	hl,bc
	ld	a,h
	ex	de,hl
	; peephole z88dk-393a
} if notUsed('hl')

replace restart {
	ld	a,c
	add	a,#0x%1
	ld	e,a
	ld	a,b
	adc	a,#0x%2
	ld	d,a
} by {
	ex	de,hl
	ld	hl,#0x%2%1
	add	hl,bc
	ld	a,h
	ex	de,hl
	; peephole z88dk-393b
}

replace restart {
	ld	a,l
	adc	a,#0x%1
	ld	e,a
	ld	a,h
	adc	a,#0x%2
	ld	d,a
} by {
	ld	de,#0x%2%1
	adc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-393c
} if notUsed('hl')

replace restart {
	ld	a,c
	add	a,#0x%1
	ld	c,a
	ld	a,b
	adc	a,#0x%2
	ld	b,a
} by {
	ld	hl,#0x%2%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393d
} if notUsed('hl')

replace restart {
	ld	hl,%1
	ld	a,c
	add	a,#0x%2
	ld	c,a
	ld	a,b
	adc	a,#0x%3
	ld	b,a
} by {
	ld	hl,#0x%3%2
	add	hl,bc
	ld	c,l
	ld	b,h
	ld	hl,%1
	; peephole z88dk-393e
}

replace restart {
	ld	hl,(%1)
	ld	a,c
	add	a,#0x%2
	ld	c,a
	ld	a,b
	adc	a,#0x%3
	ld	b,a
} by {
	ld	hl,#0x%3%2
	add	hl,bc
	ld	c,l
	ld	b,h
	ld	hl,(%1)
	; peephole z88dk-393f
}

replace restart {
	ld	hl,(%1 + %4)
	ld	a,c
	add	a,#0x%2
	ld	c,a
	ld	a,b
	adc	a,#0x%3
	ld	b,a
} by {
	ld	hl,#0x%3%2
	add	hl,bc
	ld	c,l
	ld	b,h
	ld	hl,(%1 + %4)
	; peephole z88dk-393g
}

replace restart {
	ld	hl,(%1 + %4 + %5)
	ld	a,c
	add	a,#0x%2
	ld	c,a
	ld	a,b
	adc	a,#0x%3
	ld	b,a
} by {
	ld	hl,#0x%3%2
	add	hl,bc
	ld	c,l
	ld	b,h
	ld	hl,(%1 + %4 + %5)
	; peephole z88dk-393h
}

replace restart {
	ld	a,l
	add	a,%1 (%2)
	ld	c,a
	ld	a,h
	adc	a,%3 (%4)
	ld	b,a
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	add	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-393i
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	a,#<(%1)
	add	a, c
	ld	e,a
	ld	a,#>(%1)
	adc	a, b
	ld	d,a
} by {
	ld	hl,#%1
	add	hl,bc
	ld	a,h
	ex	de,hl
	; peephole z88dk-393j1
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a, c
	ld	e,a
	ld	a,#>(%1)
	adc	a, b
	ld	d,a
} by {
	ex	de,hl
	ld	hl,#%1
	add	hl,bc
	ld	a,h
	ex	de,hl
	; peephole z88dk-393j2
}

replace restart {
	ld	a,e
	ld	hl,#%1
	add	a, c
	dec	hl
	ld	(hl),a
	ld	a,d
	adc	a, b
	inc	hl
	ld	(hl),a
} by {
	ld	l,e
	ld	h,d
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1
	; peephole z88dk-393k1
}

replace restart {
	ld	a,e
	ld	hl,#%1 + %2
	add	a, c
	dec	hl
	ld	(hl),a
	ld	a,d
	adc	a, b
	inc	hl
	ld	(hl),a
} by {
	ld	l,e
	ld	h,d
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + %2
	; peephole z88dk-393k2
}

replace restart {
	ld	a,%2 (%3)
	ld	hl,#%1
	add	a, (hl)
	ld	c,a
	ld	a,%4 (%5)
	inc	hl
	adc	a, (hl)
	ld	b,a
} by {
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-393l1
}

replace restart {
	ld	a,%2 (%3)
	ld	hl,#%1 + %9
	add	a, (hl)
	ld	c,a
	ld	a,%4 (%5)
	inc	hl
	adc	a, (hl)
	ld	b,a
} by {
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	ld	hl,(#%1 + %9)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %9 + 1
	; peephole z88dk-393l2
}

replace restart {
	ld	a,e
	ld	hl,#%1
	add	a, (hl)
	ld	(#%2),a
	ld	a,d
	ld	hl,#%1 + 1
	adc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	(#%2),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393m
}

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a, (hl)
	ld	c,a
	ld	a,b
	inc	hl
	adc	a, (hl)
	ld	b,a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-393n1
}

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a, (hl)
	ld	c,a
	ld	a,b
	inc	hl
	adc	a, (hl)
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	hl,#%1 + 1
	; peephole z88dk-393n2
}

replace restart {
	ld	a,(%1)
	add	a, #0x%3
	ld	(%2),a
	ld	a,(%1 + 1)
	adc	a, #0x%4
	ld	(%2 + 1),a
} by {
	ld	hl,(%1)
	ld	bc,#0x%4%3
	add	hl,bc
	ld	a,h
	ld	(%2),hl
	; peephole z88dk-393p1
} if notUsed('hl'), notUsed('bc')

replace restart {
	ld	a,(%1)
	add	a, #0x%3
	ld	(%2),a
	ld	a,(%1 + 1)
	adc	a, #0x%4
	ld	(%2 + 1),a
} by {
	ld	hl,(%1)
	ld	de,#0x%4%3
	add	hl,de
	ld	a,h
	ld	(%2),hl
	; peephole z88dk-393p2
} if notUsed('hl'), notUsed('de')

replace restart {
	ld	a,(%1)
	add	a, #0x%3
	ld	(%2),a
	ld	a,(%1 + 1)
	adc	a, #0x%4
	ld	(%2 + 1),a
} by {
	ld	hl,(%1)
	ld	a,l
	add	a,#0x%3
	ld	l,a
	ld	a,h
	adc	a,#0x%4
	ld	h,a
	ld	(%2),hl
	; peephole z88dk-393p3
} if notUsed('hl')

replace restart {
	ld	a,c
	sub	a, e
	ld	hl,#%1
	ld	(hl),a
	ld	a,b
	sbc	a, d
	inc	hl
	ld	(hl),a
} by {
	ld	l,c
	ld	h,b
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%1),hl
	; peephole z88dk-393q1
} if notUsed('hl')

replace restart {
	ld	a,e
	sub	a, c
	ld	hl,#%1
	ld	(hl),a
	ld	a,d
	sbc	a, b
	inc	hl
	ld	(hl),a
} by {
	ld	l,e
	ld	h,d
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%1),hl
	; peephole z88dk-393q2
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	c,a
	ld	a,#>(%1)
	inc	hl
	adc	a, (hl)
	ld	b,a
} by {
	ld	hl,(#%2)
	ld	bc,#%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%2 + 1
	; peephole z88dk-393r1
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, #0x%2
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a, #0x%3
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	bc,#0x%3%2
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-393r2
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	sbc	a, d
	ld	(hl),a
} by {
	ld	hl,(#%1)
	xor	a,a
	sbc	hl,de
	ld	(#%1),hl
	; peephole z88dk-393s
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, c
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a, b
	ld	(hl),a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	(#%1),hl
	; peephole z88dk-393t
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,b
	ld	hl,#%1 + 1
} by {
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,b
	inc	hl
	; peephole z88dk-393u
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,l
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,b
	inc	hl
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	bc,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-393v1
} if notUsed('bc')

replace restart {
	ld	c,l
	ld	b,h
	ld	a,l
	ld	hl,#%1
	sub	a, (hl)
	ld	(#%2),a
	ld	a,b
	inc	hl
	sbc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%2),hl
	ld	hl,#%1 + 1
	; peephole z88dk-393v2
} if notUsed('de')

replace restart {
	ld	e,c
	ld	d,b
	ld	hl,%1
	ld	a,e
	sub	a,l
	ld	e,a
	ld	a,d
	sbc	a,h
	ld	d,a
} by {
	ld	l,c
	ld	h,b
	ld	de,%1
	xor	a,a
	sbc	hl,de
	ex	de,hl
	; peephole z88dk-393w
} if notUsed('a')

replace restart {
	ld	a,#<(%1)
	add	a,c
	ld	c,a
	ld	a,#>(%1)
	adc	a,#0x%2
	ld	b,a
} by {
	ld	hl,#%1
	ld	b,#0x%2
	add	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-393x
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	c,l
	ld	b,h
	srl	b
	rr	c
} by {
	srl	h
	rr	l
	ld	c,l
	ld	b,h
	; peephole z88dk-393y
} if notUsed('hl')

replace restart {
	ld	a,e
	ld	hl,#%3
	adc	a,#0x%1
	inc	hl
	ld	(hl),a
	ld	a,d
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x%2%1
	adc	hl,de
	ld	a,h
	ld	(#%3 + 1),hl
	ld	hl,#%3 + 2
	; peephole z88dk-393z1
}

replace restart {
	ld	a,e
	ld	hl,#%3 + %4
	adc	a,#0x%1
	inc	hl
	ld	(hl),a
	ld	a,d
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x%2%1
	adc	hl,de
	ld	a,h
	ld	(#%3 + %4 + 1),hl
	ld	hl,#%3 + %4 + 2
	; peephole z88dk-393z2
}

replace restart {
	ld	b,h
	ld	a,l
	ld	hl,#%3
	add	a,#0x%1
	ld	(hl),a
	ld	a,b
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	bc,#0x%2%1
	add	hl,bc
	ld	a,h
	ld	(#%3),hl
	ld	hl,#%3 + 1
	; peephole z88dk-393aa1
} if notUsed('bc')

replace restart {
	ld	b,h
	ld	a,l
	ld	hl,#%3
	add	a,#0x%1
	ld	(hl),a
	ld	a,b
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	b,h
	ld	de,#0x%2%1
	add	hl,de
	ld	a,h
	ld	(#%3),hl
	ld	hl,#%3 + 1
	; peephole z88dk-393aa2
} if notUsed('de')

replace restart {
	ld	b,h
	ld	a,l
	ld	hl,#%3 + %4
	add	a,#0x%1
	ld	(hl),a
	ld	a,b
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	bc,#0x%2%1
	add	hl,bc
	ld	a,h
	ld	(#%3 + %4),hl
	ld	hl,#%3 + %4 + 1
	; peephole z88dk-393aa3
} if notUsed('bc')

replace restart {
	ld	b,h
	ld	a,l
	ld	hl,#%3 + %4
	add	a,#0x%1
	ld	(hl),a
	ld	a,b
	adc	a,#0x%2
	inc	hl
	ld	(hl),a
} by {
	ld	b,h
	ld	de,#0x%2%1
	add	hl,de
	ld	a,h
	ld	(#%3 + %4),hl
	ld	hl,#%3 + %4 + 1
	; peephole z88dk-393aa4
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	ld	a,e
	add	a,c
	ld	c,a
	ld	a,d
	adc	a,b
	ld	b,a
} by {
	add	hl,de
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393ab
} if notUsed('hl')

replace restart {
	ld	a,e
	sub	a,c
	ld	c,a
	ld	a,d
	sbc	a,b
	ld	b,a
	push	bc
} by {
	ex	de,hl
	xor	a,a
	sbc	hl,bc
	push	hl
	; peephole z88dk-393ac
} if notUsed('hl'), notUsed('de'), notUsed('bc'), notUsed('a')

replace restart {
	ld	a,#0x%1
	sub	a,c
	ld	c,a
	ld	a,#0x%2
	sbc	a,b
	ld	b,a
	ld	a,e
	sub	a,c
	ld	a,d
	sbc	a,b
} by {
	ld	hl,#0x%2%1
	xor	a,a
	sbc	hl,bc
	ld	a,e
	sub	a,l
	ld	a,d
	sbc	a,h
	; peephole z88dk-393ad
} if notUsed('hl'), notUsed('bc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	xor	a,a
	sbc	hl,bc
} by {
	ex	de,hl
	ld	hl,%1
	xor	a,a
	sbc	hl,de
	; peephole z88dk-393ae
} if notUsed('bc'), notUsed('de')

replace restart {
	ld	a,#<(%1)
	add	a,l
	ld	%2 (%3),a
	ld	a,#>(%1)
	adc	a,h
	ld	l,%2 (%3)
	ld	%4 (%5),a
	ld	h,a
} by {
	ld	bc,#%1
	add	hl,bc
	ld	%2 (%3),l
	ld	%4 (%5),h
	ld	a,h
	; peephole z88dk-393af1
} if notUsed('bc')

replace restart {
	ld	a,#<(%1)
	add	a,l
	ld	%2 (%3),a
	ld	a,#>(%1)
	adc	a,h
	ld	l,%2 (%3)
	ld	%4 (%5),a
	ld	h,a
} by {
	ld	de,#%1
	add	hl,de
	ld	%2 (%3),l
	ld	%4 (%5),h
	ld	a,h
	; peephole z88dk-393af2
} if notUsed('de')

replace restart {
	ld	a,c
	add	a,%1
	ld	c,a
	ld	a,b
	adc	a,%2
	ld	b,a
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	a,c
	add	a,%1
	ld	(hl),a
	ld	c,a
	ld	a,b
	adc	a,%2
	inc	hl
	ld	(hl),a
	ld	b,a
	; peephole z88dk-393ag
} if notSame(%2 '(hl)')

replace restart {
	ld	%1 (%2),a
	ld	a,%3
	adc	a,%4
	ld	%5,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%5,a
	ld	a,%3
	adc	a,%4
	; peephole z88dk-393ah
} if notSame(%5 'a'), notSame(%5 %3), notSame(%5 %4)

replace restart {
	ld	a, (hl)
	inc	hl
	ld	h,(hl)
	add	a,#<(%1)
	ld	l,a
	ld	a,#>(%1)
	adc	a, h
	ld	h,a
} by {
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	ld	hl,#%1
	add	hl,bc
	ld	a,h
	; peephole z88dk-393ai1
} if notUsed('bc')

replace restart {
	ld	a, (hl)
	inc	hl
	ld	h,(hl)
	add	a,#<(%1)
	ld	l,a
	ld	a,#>(%1)
	adc	a, h
	ld	h,a
} by {
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ld	hl,#%1
	add	hl,de
	ld	a,h
	; peephole z88dk-393ai2
} if notUsed('de')

replace restart {
	ld	a,#<(%1)
	add	a,%2 (%3)
	ld	l,a
	ld	a,#>(%1)
	adc	a,%4 (%5)
	ld	h,a
} by {
	ld	bc,#%1
	ld	l,%2 (%3)
	ld	h,%4 (%5)
	add	hl,bc
	ld	a,h
	; peephole z88dk-393aj1
} if notUsed('bc')

replace restart {
	ld	a,#<(%1)
	add	a,%2 (%3)
	ld	l,a
	ld	a,#>(%1)
	adc	a,%4 (%5)
	ld	h,a
} by {
	ld	de,#%1
	ld	l,%2 (%3)
	ld	h,%4 (%5)
	add	hl,de
	ld	a,h
	; peephole z88dk-393aj2
} if notUsed('de')

replace restart {
	ld	a,#<(%1)
	add	a,%2 (%3)
	ld	%4 (%5),a
	ld	l,a
	ld	a,#>(%1)
	adc	a,#%6
	ld	%7 (%8),a
	ld	h,a
} by {
	ld	bc,#%1
	ld	l,%2 (%3)
	ld	h,#%6
	add	hl,bc
	ld	%4 (%5),l
	ld	%7 (%8),h
	ld	a,h
	; peephole z88dk-393k1
} if notUsed('bc')

replace restart {
	ld	a,#<(%1)
	add	a,%2 (%3)
	ld	%4 (%5),a
	ld	l,a
	ld	a,#>(%1)
	adc	a,#%6
	ld	%7 (%8),a
	ld	h,a
} by {
	ld	de,#%1
	ld	l,%2 (%3)
	ld	h,#%6
	add	hl,de
	ld	%4 (%5),l
	ld	%7 (%8),h
	ld	a,h
	; peephole z88dk-393k2
} if notUsed('de')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	e,%2 (%3)
	ld	d,%4 (%5)
	add	hl,de
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-393l1
} if notUsed('a'), notUsed('de')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	add	hl,bc
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-393l2
} if notUsed('a'), notUsed('bc')

replace restart {
	ld	hl,#%1 + %6
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
} by {
	ld	hl,(#%1 + %6)
	ld	e,%2 (%3)
	ld	d,%4 (%5)
	add	hl,de
	ld	(#%1 + %6),hl
	ld	hl,#%1 + %6 + 1
	; peephole z88dk-393l3
} if notUsed('a'), notUsed('de')

replace restart {
	ld	hl,#%1 + %6
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
} by {
	ld	hl,(#%1 + %6)
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	add	hl,bc
	ld	(#%1 + %6),hl
	ld	hl,#%1 + %6 + 1
	; peephole z88dk-393l4
} if notUsed('a'), notUsed('bc')

replace restart {
	ld	a,e
	add	a,#0x%1
	ld	%3 (%4),a
	ld	a,d
	adc	a,#0x%2
	ld	%5 (%6),a
} by {
	ld	hl,#0x%2%1
	add	hl,de
	ld	%3 (%4),l
	ld	%5 (%6),h
	; peephole z88dk-393m
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	a,e
	ld	hl,#%1
	sub	a,(hl)
	ld	%3 (%4),a
	ld	a,d
	inc	hl
	sbc	a,(hl)
	ld	%5 (%6),a
} by {
	ld	hl,(#%1)
	ex	de,hl
	xor	a,a
	sbc	hl,de
	ld	%3 (%4),l
	ld	%5 (%6),h
	ld	hl,#%1 + 1
	; peephole z88dk-393n1
} if notUsed('de'), notUsed('a')

replace restart {
	ld	a,e
	ld	hl,#%1
	sbc	a,(hl)
	ld	%3 (%4),a
	ld	a,d
	inc	hl
	sbc	a,(hl)
	ld	%5 (%6),a
} by {
	ld	hl,(#%1)
	ex	de,hl
	sbc	hl,de
	ld	%3 (%4),l
	ld	%5 (%6),h
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393n2
} if notUsed('de')

replace restart {
	ld	a,e
	ld	hl,#%1 + %2
	sub	a,(hl)
	ld	%3 (%4),a
	ld	a,d
	inc	hl
	sbc	a,(hl)
	ld	%5 (%6),a
} by {
	ld	hl,(#%1 + %2)
	ex	de,hl
	xor	a,a
	sbc	hl,de
	ld	%3 (%4),l
	ld	%5 (%6),h
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-393n3
} if notUsed('de'), notUsed('a')

replace restart {
	ld	a,e
	ld	hl,#%1 + %2
	sbc	a,(hl)
	ld	%3 (%4),a
	ld	a,d
	inc	hl
	sbc	a,(hl)
	ld	%5 (%6),a
} by {
	ld	hl,(#%1 + %2)
	ex	de,hl
	sbc	hl,de
	ld	%3 (%4),l
	ld	%5 (%6),h
	ld	a,h
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-393n4
} if notUsed('de')

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%3
	ld	c,a
	ld	a,%5 (%6)
	adc	a,#0x%4
	ld	b,a
	ld	l,c
	ld	h,a
} by {
	ld	l,%1 (%2)
	ld	h,%5 (%6)
	ld	bc,#0x%4%3
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393o
}

replace restart {
	ld	a,%1 (%2)
	add	a,l
	ld	c,a
	ld	a,%3 (%4)
	adc	a,h
	ld	b,a
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393p1
} if notUsed('hl')

replace restart {
	ld	b,h
	ld	a,l
	add	a,%1 (%2)
	ld	c,a
	ld	a,b
	adc	a,%3 (%4)
	ld	b,a
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393p2
} if notUsed('hl')

replace restart {
	ld	a,%1 (%2)
	add	a,c
	ld	e,a
	ld	a,%3 (%4)
	adc	a,b
	ld	d,a
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	add	hl,bc
	ld	a,h
	ex	de,hl
	; peephole z88dk-393q
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a,%4 (%5)
	ld	%2 (%3),a
	ld	a,#>(%1)
	adc	a,%6 (%7)
	ld	l,%2 (%3)
	ld	%8 (%9),a
	ld	h,a
} by {
	ld	l,%4 (%5)
	ld	h,%6 (%7)
	ld	bc,#%1
	add	hl,bc
	ld	%2 (%3),l
	ld	%8 (%9),h
	ld	a,h
	; peephole z88dk-393r1
} if notUsed('bc')

replace restart {
	ld	a,#<(%1)
	add	a,%4 (%5)
	ld	%2 (%3),a
	ld	a,#>(%1)
	adc	a,%6 (%7)
	ld	l,%2 (%3)
	ld	%8 (%9),a
	ld	h,a
} by {
	ld	l,%4 (%5)
	ld	h,%6 (%7)
	ld	de,#%1
	add	hl,de
	ld	%2 (%3),l
	ld	%8 (%9),h
	ld	a,h
	; peephole z88dk-393r2
} if notUsed('de')

replace restart {
	ld	c,l
	ld	b,h
	ld	a,%1 (%2)
	add	a,c
	ld	c,a
	ld	a,%3 (%4)
	adc	a,b
	ld	b,a
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393s1
} if notUsed('hl')

replace restart {
	ld	a,%1 (%2)
	add	a,c
	ld	c,a
	ld	a,%3 (%4)
	adc	a,b
	ld	l,c
	ld	h,a
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	add	hl,bc
	ld	a,h
	ld	c,l
	; peephole z88dk-393s2
}

replace restart {
	ld	c,l
	ld	b,h
	ld	l,%3 (%4)
	ld	h,%5 (%6)
	add	hl,bc
} by {
	ld	c,%3 (%4)
	ld	b,%5 (%6)
	add	hl,bc
	; peephole z88dk-393s3
} if notUsed('bc')

replace restart {
	ex	de,hl
	ld	l,%3 (%4)
	ld	h,%5 (%6)
	add	hl,de
} by {
	ld	e,%3 (%4)
	ld	d,%5 (%6)
	add	hl,de
	; peephole z88dk-393s4
} if notUsed('de')

replace restart {
	ld	b,h
	ld	a,l
	ld	hl,#%1
	sub	a,(hl)
	ld	(%2),a
	ld	a,b
	inc	hl
	sbc	a, (hl)
	ld	(%2 + 1),a
} by {
	ld	bc,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	(%2),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393t1
} if notUsed('bc')

replace restart {
	ld	b,h
	ld	a,l
	ld	hl,#%1
	sub	a,(hl)
	ld	(%2),a
	ld	a,b
	inc	hl
	sbc	a, (hl)
	ld	(%2 + 1),a
} by {
	ld	b,h
	ld	de,(#%1)
	xor	a,a
	sbc	hl,de
	ld	(%2),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393t2
} if notUsed('de')

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%9
	ld	%5 (%6),a
	ld	l,a
	ld	a,%3 (%4)
	adc	a,#0x%10
	ld	%7 (%8),a
	ld	h,a
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	de,#0x%10%9
	add	hl,de
	ld	%5 (%6),l
	ld	%7 (%8),h
	ld	a,h
	; peephole z88dk-393u1
} if notUsed('de')

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%9
	ld	%5 (%6),a
	ld	l,a
	ld	a,%3 (%4)
	adc	a,#0x%10
	ld	%7 (%8),a
	ld	h,a
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	bc,#0x%10%9
	add	hl,bc
	ld	%5 (%6),l
	ld	%7 (%8),h
	ld	a,h
	; peephole z88dk-393u2
} if notUsed('bc')

replace restart {
	ex	de,hl
	ld	a,%1 (%2)
	add	a, e
	ld	%5 (%6),a
	ld	a,%3 (%4)
	adc	a, d
	ld	%7 (%8),a
} by {
	ld	e,%1 (%2)
	ld	d,%3 (%4)
	add	hl,de
	ld	%5 (%6),l
	ld	%7 (%8),h
	ld	a,h
	; peephole z88dk-393v1
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a, d
	ld	(hl),a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393w1
}

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	add	a, e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a, d
	ld	(hl),a
} by {
	ld	hl,(#%1 + %2)
	add	hl,de
	ld	(#%1 + %2),hl
	ld	a,h
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-393w2
}

replace restart {
	ld	hl,#%8
	add	a,(hl)
	ld	%1 (%2),a
	ld	a,%3 (%4)
	inc	hl
	adc	a,(hl)
	ld	%5 (%6),a
} by {
	ld	hl,(#%8)
	add	a,l
	ld	%1 (%2),a
	ld	a,%3 (%4)
	adc	a,h
	ld	%5 (%6),a
	; peephole z88dk-393x1
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	add	hl,bc
	ld	(#%1),hl
	; peephole z88dk-393y1
} if notUsed('bc'), notUsed('hl'), notUsed('a')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
	inc	hl
} by {
	ld	hl,(#%1)
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 2
	; peephole z88dk-393y2
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	e,%2 (%3)
	ld	d,%4 (%5)
	add	hl,de
	ld	(#%1),hl
	; peephole z88dk-393y3
} if notUsed('de'), notUsed('hl'), notUsed('a')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	(hl),a
	inc	hl
} by {
	ld	hl,(#%1)
	ld	e,%2 (%3)
	ld	d,%4 (%5)
	add	hl,de
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 2
	; peephole z88dk-393y4
} if notUsed('de')

replace restart {
	ld	hl,#%2
	ld	a,(hl)
	add	a,c
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#%1
	ld	(hl),a
	ld	d,a
	dec	hl
	ld	e,(hl)
} by {
	ld	hl,(#%2)
	ld	b,#%1
	add	hl,bc
	ld	a,h
	ld	(#%2),hl
	ex	de,hl
	ld	hl,#%2
	; peephole z88dk-393z1
} if notUsed('b')

replace restart {
	ld	hl,#%2 + %3
	ld	a,(hl)
	add	a,c
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#%1
	ld	(hl),a
	ld	d,a
	dec	hl
	ld	e,(hl)
} by {
	ld	hl,(#%2 + %3)
	ld	b,#%1
	add	hl,bc
	ld	a,h
	ld	(#%2 + %3),hl
	ex	de,hl
	ld	hl,#%2 + %3
	; peephole z88dk-393z2
} if notUsed('b')

replace restart {
	ld	%3,h
	ld	a,l
	ld	hl,#%1
	add	a, (hl)
	ld	(#%2),a
	ld	a,%3
	ld	hl,#%1 + 1
	adc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ex	de,hl
	ld	hl,(#%1)
	add	hl,de
	ld	(#%2),hl
	ld	a,h
	ld	hl,#%1 + 1
	ld	%3,d
	; peephole z88dk-393aa1
} if notUsed('de'), notVolatile(%3)

replace restart {
	ld	%3,h
	ld	a,l
	ld	hl,#%1
	add	a, (hl)
	ld	(#%2),a
	ld	a,%3
	ld	hl,#%1 + 1
	adc	a, (hl)
	ld	(#%2 + 1),a
} by {
	ld	%3,h
	ld	bc,(#%1)
	add	hl,bc
	ld	(#%2),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393aa2
} if notUsed('bc'), operandsNotRelated(%3 'bc'), notVolatile(%3)

replace restart {
	ld	b,h
	ld	a,l
	add	a,#0x%1
	ld	c,a
	ld	a,b
	adc	a,#0x%2
	ld	b,a
} by {
	ld	bc,#0x%2%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-393ab
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a, c
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a, b
	ld	d,a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ex	de,hl
	ld	a,d
	ld	hl,#%1 + 1
	; peephole z88dk-393ac
}

replace restart {
	ld	a,c
	ld	hl,#%1 + 1
	add	a, e
	dec	hl
	ld	(hl),a
	ld	a,b
	adc	a, d
	inc	hl
	ld	(hl),a
} by {
	ld	l,e
	ld	h,d
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-393ad
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,%4 (%5)
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	c,%2 (%3)
	ld	b,%4 (%5)
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-393ae
}

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%5
	ld	hl,#%7
	ld	(hl),a
	ld	a,%3 (%4)
	adc	a,#0x%6
	inc	hl
	ld	(hl),a
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	de,#0x%6%5
	add	hl,de
	ld	a,h
	ld	(#%7),hl
	ld	hl,#%7 + 1
	; peephole z88dk-393af1
} if notUsed('de')

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%5
	ld	hl,#%7
	ld	(hl),a
	ld	a,%3 (%4)
	adc	a,#0x%6
	inc	hl
	ld	(hl),a
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	bc,#0x%6%5
	add	hl,bc
	ld	a,h
	ld	(#%7),hl
	ld	hl,#%7 + 1
	; peephole z88dk-393af2
} if notUsed('bc')

replace restart {
	ld	a,#0x%1
	ld	hl,#%3
	sub	a, (hl)
	ld	(#%4),a
	ld	a,#0x%2
	ld	hl,#%3 + 1
	sbc	a, (hl)
	ld	(#%4 + 1),a
} by {
	ld	hl,#0x%2%1
	ld	de,(#%3)
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	(#%4),hl
	ld	hl,#%3 + 1
	; peephole z88dk-393ag1
} if notUsed('de')

replace restart {
	ld	a,#0x%1
	ld	hl,#%3
	sub	a, (hl)
	ld	(#%4),a
	ld	a,#0x%2
	ld	hl,#%3 + 1
	sbc	a, (hl)
	ld	(#%4 + 1),a
} by {
	ld	hl,#0x%2%1
	ld	bc,(#%3)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	(#%4),hl
	ld	hl,#%3 + 1
	; peephole z88dk-393ag2
} if notUsed('bc')

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%3
	ld	l,a
	ld	a,%4 (%5)
	adc	a,#0x%6
	ld	h,a
} by {
	ld	l,%1 (%2)
	ld	h,%4 (%5)
	ld	de,#0x%6%3
	add	hl,de
	; peephole z88dk-393ah1
} if notUsed('de'), notUsed('a')

replace restart {
	ld	a,%1 (%2)
	add	a,#0x%3
	ld	l,a
	ld	a,%4 (%5)
	adc	a,#0x%6
	ld	h,a
} by {
	ld	l,%1 (%2)
	ld	h,%4 (%5)
	ld	bc,#0x%6%3
	add	hl,bc
	; peephole z88dk-393ah2
} if notUsed('bc'), notUsed('a')











replace restart {
	inc	sp
	inc	sp
} by {
	pop	bc
	; peephole z88dk-394a
} if notUsed('bc')

replace restart {
	inc	sp
	inc	sp
} by {
	pop	de
	; peephole z88dk-394b
} if notUsed('de')

replace restart {
	inc	sp
	inc	sp
} by {
	pop	hl
	; peephole z88dk-394c
} if notUsed('hl')

//replace restart {
//	inc	sp
//	inc	sp
//} by {
//	pop	af
//	; peephole z88dk-394d  INCORRECT IF FLAGS TESTED
//} if notUsed('a')

replace restart {
	ld	hl,#%1
	ld	c, l
	ld	b, h
} by {
	ld	bc,#%1
	; peephole z88dk-395a
} if notUsed('hl')

replace restart {
	ld	bc,#%1
	ld	e,c
	ld	d,b
} by {
	ld	de,#%1
	; peephole z88dk-395b
} if notUsed('bc')

replace restart {
	ld	e,c
	ld	d,b
	ld	%1,de
} by {
	ld	%1,bc
	ld	e,c
	ld	d,b
	; peephole z88dk-395c
}

replace restart {
	ld	%1,(hl)
	bit	%2,%1
} by {
	bit	%2,(hl)
	; peephole z88dk-396a
} if notUsed(%1)

replace restart {
	ld	%1,(hl)
	res	%2,%1
	ld	(hl),%1
} by {
	res	%2,(hl)
	; peephole z88dk-396b
} if notUsed(%1)

replace restart {
	ld	%1,(hl)
	set	%2,%1
	ld	(hl),%1
} by {
	set	%2,(hl)
	; peephole z88dk-396c
} if notUsed(%1)

replace restart {
	ld	l, c
	ld	h, b
	push	bc
	ld	bc, %1
	add	hl, bc
	pop	bc
} by {
	ld	hl,%1
	add	hl,bc
	; peephole z88dk-397a
}

replace restart {
	push	%4
	ld	%1,%2
	dec	%3
	pop	%4
} by {
	ld	%1,%2
	dec	%3
	; peephole z88dk-397b
} if operandsNotRelated(%1 %4), operandsNotRelated(%3 %4)

replace restart {
	push	%4
	ld	%1,%2
	inc	%3
	pop	%4
} by {
	ld	%1,%2
	inc	%3
	; peephole z88dk-397c
} if operandsNotRelated(%1 %4), operandsNotRelated(%3 %4)

replace restart {
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
	ld	%7,%8
	dec	%9
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
} by {
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
	ld	%7,%8
	dec	%9
	; peephole z88dk-397d
} if operandsNotRelated(%1 %7), operandsNotRelated(%1 %9), operandsNotRelated(%2 %7), operandsNotRelated(%2 %9)
// notVolatile

replace restart {
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
	ld	%7,%8
	inc	%9
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
} by {
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
	ld	%7,%8
	inc	%9
	; peephole z88dk-397d
} if operandsNotRelated(%1 %7), operandsNotRelated(%1 %9), operandsNotRelated(%2 %7), operandsNotRelated(%2 %9)
// notVolatile

replace restart {
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
	ld	%7,%8
	set	%9,%10
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
} by {
	ld	%1,%3 (%5)
	ld	%2,%4 (%6)
	ld	%7,%8
	set	%9,%10
	; peephole z88dk-397e
} if operandsNotRelated(%1 %7), operandsNotRelated(%1 %10), operandsNotRelated(%2 %7), operandsNotRelated(%2 %10)
// not Volatile

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7,%8
	ld	%3,%1 (%2)
	ld	%6,%4 (%5)
} by {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7,%8
	; peephole z88dk-397f
} if operandsNotRelated(%7 %3), operandsNotRelated(%7 %6)
// notVolatile

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7,(%8)
	ld	%3,%1 (%2)
	ld	%6,%4 (%5)
} by {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7,(%8)
	; peephole z88dk-397g
} if operandsNotRelated(%7 %3), operandsNotRelated(%7 %6)
// notVolatile

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7,(%8 + %9)
	ld	%3,%1 (%2)
	ld	%6,%4 (%5)
} by {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7,(%8 + %9)
	; peephole z88dk-397h
} if operandsNotRelated(%7 %3), operandsNotRelated(%7 %6)
// notVolatile

replace restart {
	ld	%1,%2 (%3)
	ld	%5,%6 (%7)
	ld	%9,%10
	ld	%4,%2 (%3)
	ld	%8,%6 (%7)
} by {
	ld	%1,%2 (%3)
	ld	%5,%6 (%7)
	ld	%9,%10
	ld	%4,%1
	ld	%8,%5
	; peephole z88dk-397i
} if operandsNotRelated(%9 %1), operandsNotRelated(%9 %5), canAssign(%4 %1), canAssign(%8 %5)
//notVolatile 

replace restart {
	ld	%2 (%3),%1
	ld	%4,%5
	ld	%6,%7 (%8)
	ld	%1,%2 (%3)
} by {
	ld	%2 (%3),%1
	ld	%4,%5
	ld	%6,%7 (%8)
	; peephole z88dk-397j1
} if operandsNotRelated(%1 %4), operandsNotRelated(%1 %6)
// notVolatile

replace restart {
	ld	b,l
	ld	c,h
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	l,b
	ld	h,c
} by {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	b,l
	ld	c,h
	; peephole z88dk-397k
} if operandsNotRelated(%1 'bc'), operandsNotRelated(%1 'hl'), operandsNotRelated(%4 'bc'), operandsNotRelated(%4 'hl')

replace restart {
	ld	%2 (%3),%1
	ld	%6,%7 (%8)
	ld	%1,%2 (%3)
} by {
	ld	%2 (%3),%1
	ld	%6,%7 (%8)
	; peephole z88dk-397j1
} if operandsNotRelated(%1 %6)
// notVolatile

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	a,%7
	%8	a,%1 (%2)
} by {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	a,%7
	%8	a,%3
	; peephole z88dk-397k1
} if notSame(%3 'a')
// if notVolatile

replace restart {
	ld	%1 (%2),%3
	ld	a,%4
	%8	a,%5
	ld	%6,a
	ld	a,%7
	%9	a,%1 (%2)
} by {
	ld	%1 (%2),%3
	ld	a,%4
	%8	a,%5
	ld	%6,a
	ld	a,%7
	%9	a,%3
	; peephole z88dk-397k2
} if notSame(%6 %3), notSame(%3 'a')
// if notVolatile

replace restart {
	ld	%1 (%2),a
	ld	%3 (%4),%5
	ld	a,%6
	%7	a,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%3 (%4),%5
	%7	a,%6
	; peephole z88dk-397k3
} if same(%7 'add' 'or' 'and' 'xor')

replace restart {
	ld	%1 (%2),%3
	%9	a,%4
	ld	%5,%6
	ld	%7,%8
	%10	a,%1 (%2)
} by {
	ld	%1 (%2),%3
	%9	a,%4
	ld	%5,%6
	ld	%7,%8
	%10	a,%3
	; peephole z88dk-397k4
} if notSame(%3 'a'), operandsNotRelated(%5 %3), operandsNotRelated(%7 %3)

replace restart {
	ld	%1 (%2),%3
	bit	%4,%1 (%2)
} by {
	ld	%1 (%2),%3
	bit	%4,%3
	; peephole z88dk-397l
} if canAssign(%3 '(hl)')
// if notVolatile

replace restart {
	ld	d,(hl)
	ld	e,%1
	ld	a,d
} by {
	ld	a,(hl)
	ld	e,%1
	ld	d,a
	; peephole z88dk-398a1
} if notSame(%1 'a'), notSame(%1 'd')

replace restart {
	ld	b,(hl)
	ld	c,%1
	ld	a,b
} by {
	ld	a,(hl)
	ld	c,%1
	ld	b,a
	; peephole z88dk-398b
} if notSame(%1 'a'), notSame(%1 'b')

replace restart {
	ld	d,(hl)
	ld	c,%1
	ld	a,d
} by {
	ld	a,(hl)
	ld	c,%1
	ld	d,a
	; peephole z88dk-398c
} if notSame(%1 'a'), notSame(%1 'd')

replace restart {
	ld	bc,(%1)
	ld	a,b
	or	a,c
} by {
	ld	hl,(%1)
	ld	a,h
	or	a,l
	; peephole z88dk-399a
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	bc,(%1 + %2)
	ld	a,b
	or	a,c
} by {
	ld	hl,(%1 + %2)
	ld	a,h
	or	a,l
	; peephole z88dk-399b
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	de,(%1)
	ld	a,d
	or	a,e
} by {
	ld	hl,(%1)
	ld	a,h
	or	a,l
	; peephole z88dk-399c
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	de,(%1 + %2)
	ld	a,d
	or	a,e
} by {
	ld	hl,(%1 + %2)
	ld	a,h
	or	a,l
	; peephole z88dk-399d
} if notUsed('de'), notUsed('hl')

replace restart {
	push	hl
	ld	de,%1
	add	hl,de
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	pop	hl
} by {
	ld	de,%1
	add	hl,de
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	; peephole z88dk-400a1
} if notUsed('hl')

replace restart {
	push	hl
	ld	de,%1
	add	hl,de
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	pop	hl
} by {
	ex	de,hl
	ld	hl,%1
	add	hl,de
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	ex	de,hl
	; peephole z88dk-400a2
} if notUsed('de')

replace restart {
	push	hl
	push	bc
	ld	de,%1
	add	hl,de
	ld	c,(hl)
	inc	hl
	pop	de
	ld	b,(hl)
	pop	hl
} by {
	push	bc
	ex	de,hl
	ld	hl,%1
	add	hl,de
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	ex	de,hl
	pop	de
	; peephole z88dk-400b
}

replace restart {
	push	%1
	ld	%2,(%1)
	ld	%4 (%5),%6
	inc	%1
	ld	%3,(%1)
	ld	%7 (%8),%9
	pop	%1
} by {
	ld	%2,(%1)
	ld	%4 (%5),%6
	inc	%1
	ld	%3,(%1)
	ld	%7 (%8),%9
	dec	%1
	; peephole z88dk-401
} if operandsNotRelated(%2 %1), operandsNotRelated(%3 %1)

replace restart {
	ld	c,l
	ld	b,h
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	a,b
	or	a,c
} by {
	ld	c,l
	ld	b,h
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	a,h
	or	a,l
	; peephole z88dk-403a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	push	bc
} by {
	ld	c,l
	ld	b,h
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	push	hl
	; peephole z88dk-403b
} if operandsNotRelated(%1 'hl'), operandsNotRelated(%4 'hl')

replace restart {
	ld	%1 (%2),#%3
	ld	%4,#%3
} by {
	ld	%4,#%3
	ld	%1 (%2),%4
	; peephole z88dk-404a
} if canAssign(%1 %2 %4)

replace restart {
	ld	%7,#%1
	ld	%8,#%2
	ld	%3 (%4),#%1
	ld	%5 (%6),#%2
} by {
	ld	%7,#%1
	ld	%8,#%2
	ld	%3 (%4),%7
	ld	%5 (%6),%8
	; peephole z88dk-404b
} if notSame(%7 %8), canAssign(%3 %4 %7), canAssign(%5 %6 %8)

replace restart {
	ld	%1,#<(%3)
	ld	%4 (%5),%1
	ld	%2,#>(%3)
	ld	%6 (%7),%2
} by {
	ld	%1,#<(%3)
	ld	%2,#>(%3)
	ld	%4 (%5),%1
	ld	%6 (%7),%2
	; peephole z88dk-405a
} if notSame(%1 %2)

replace restart {
	ld	%1,#%3
	ld	%4 (%5),%1
	ld	%2,#%8
	ld	%6 (%7),%2
} by {
	ld	%1,#%3
	ld	%2,#%8
	ld	%4 (%5),%1
	ld	%6 (%7),%2
	; peephole z88dk-405b
} if notSame(%1 %2)

replace restart {
	ld	e,#<(%1)
	ld	d,#>(%1)
} by {
	ld	de,#%1
	; peephole z88dk-406a
}

replace restart {
	ld	c,#<(%1)
	ld	b,#>(%1)
} by {
	ld	bc,#%1
	; peephole z88dk-406b
}

replace restart {
	ld	l,#<(%1)
	ld	h,#>(%1)
} by {
	ld	hl,#%1
	; peephole z88dk-406c
}

replace restart {
	ld	bc,(%1)
	ld	hl,%2
	add	hl,bc
	ld	c,l
	ld	b,h
} by {
	ld	hl,(%1)
	ld	bc,%2
	add	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-407a
}

replace restart {
	ld	bc,(%1 + %3)
	ld	hl,%2
	add	hl,bc
	ld	c,l
	ld	b,h
} by {
	ld	hl,(%1 + %3)
	ld	bc,%2
	add	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-407b
}

replace restart {
	ld	bc,(%1)
	ld	hl,%2
	add	hl,bc
} by {
	ld	hl,(%1)
	ld	bc,%2
	add	hl,bc
	; peephole z88dk-407c
} if notUsed('bc')

replace restart {
	ld	bc,(%1 + %3)
	ld	hl,%2
	add	hl,bc
} by {
	ld	hl,(%1 + %3)
	ld	bc,%2
	add	hl,bc
	; peephole z88dk-407d
} if notUsed('bc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	add	hl,bc
} by {
	ld	bc,%1
	add	hl,bc
	; peephole z88dk-407e
} if notUsed('bc')

replace restart {
	ld	l,c
	ld	h,b
	ld	bc,%1
	add	hl,bc
} by {
	ld	hl,%1
	add	hl,bc
	; peephole z88dk-407f
} if notUsed('bc')

replace restart {
	ld	e,l
	ld	d,h
	push	bc
	ld	bc,%1
	add	hl, bc
	pop	bc
} by {
	ld	e,l
	ld	d,h
	ld	hl,%1
	add	hl,de
	; peephole z88dk-407e
}

replace restart {
	push	%2
	ld	%2,#%1
	add	hl,%2
	pop	%2
} by {
	ld	a,#<(%1)
	add	a,l
	ld	l,a
	ld	a,#>(%1)
	adc	a,h
	ld	h,a
	; peephole z88dk-407f
} if notUsed('a')

replace restart {
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	ld	a,c
} by {
	ld	a,(hl)
	inc	hl
	ld	b,(hl)
	ld	c,a
	; peephole z88dk-408a
}

replace restart {
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ld	a,e
} by {
	ld	a,(hl)
	inc	hl
	ld	d,(hl)
	ld	e,a
	; peephole z88dk-408b
}

replace restart {
	ld	c,l
	ld	b,h
	ld	(%1),hl
	ld	l,c
	ld	h,b
} by {
	ld	(%1),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-409a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	de,#%1
	ld	l,c
	ld	h,b
} by {
	ld	de,#%1
	ld	c,l
	ld	b,h
	; peephole z88dk-409b
}

replace restart {
	ld	%1,#0x00
	and	a,%2
	or	a,%1
} by {
	ld	%1,#0x00
	and	a,%2
	; peephole z88dk-410
}
// notVolatile

replace restart {
	ld	b,#0x09
%1:
	srl	d
	rr	e
	rr	l
	rr	c
	djnz	%1
} by {
	ld	c,l
	ld	l,e
	ld	e,d
	ld	d,#0x00
	ld	b,d
	srl	d
	rr	e
	rr	l
	rr	c
	; peephole z88dk-411a
}

replace restart {
	ld	a,#0x10
%1:
	srl	h
	rr	l
	rr	d
	rr	e
	dec	a
	%2	NZ,%1
} by {
	ld	d,h
	ld	e,l
	ld	hl,#0x0000
	; peephole z88dk-411b
} if notUsed('a')

replace restart {
	ld	a,#0x10
%1:
	srl	h
	rr	l
	rr	d
	rr	e
	dec	a
	%2	NZ,%1
} by {
	ld	d,h
	ld	e,l
	xor	a,a
	ld	l,a
	ld	h,a
	; peephole z88dk-411c
}

replace restart {
	ld	b,#0x09
%1:
	sra	l
	rr	c
	rr	d
	rr	e
	djnz	%1
} by {
	ld	e,d
	ld	d,c
	ld	c,l
	ld	a,l
	add	a,a
	sbc	a,a
	ld	l,a
	rr	c
	rr	d
	rr	e
	ld	b,#0x00
	; peephole z88dk-411d
} if notUsed('a')

replace restart {
	ld	b,#0x09
%1:
	sra	l
	rr	c
	rr	d
	rr	e
	djnz	%1
} by {
	ld	b,a
	ld	e,d
	ld	d,c
	ld	c,l
	ld	a,l
	add	a,a
	sbc	a,a
	ld	l,a
	rr	c
	rr	d
	rr	e
	ld	a,b
	ld	b,#0x00
	; peephole z88dk-411e
}

replace restart {
	ld	b,#0x19
%1:
	sra	l
	rr	d
	rr	e
	rr	c
	djnz	%1
} by {
	ld	c,l
	ld	a,l
	add	a,a
	sbc	a,a
	ld	e,a
	ld	d,a
	ld	l,a
	rr	e
	ld	b,#0x00
	; peephole z88dk-411f
} if notUsed('a')

replace restart {
	ld	b,#0x19
%1:
	sra	l
	rr	d
	rr	e
	rr	c
	djnz	%1
} by {
	ld	b,a
	ld	c,l
	ld	a,l
	add	a,a
	sbc	a,a
	ld	e,a
	ld	d,a
	ld	l,a
	rr	e
	ld	a,b
	ld	b,#0x00
	; peephole z88dk-411g
}

replace restart {
	ld	b,%2
%1:
	sra	%3 (%4)
	rr	%5 (%6)
	djnz	%1
} by {
	ld	b,%2
	ld	c,%3 (%4)
	ld	a,%5 (%6)
%1:
	sra	c
	rra
	djnz	%1
	ld	%3 (%4),c
	ld	%5 (%6),a
	; peephole z88dk-411h1
} if notUsed('a'), notUsed('c')
// notVolatile

replace restart {
	ld	b,%2
%1:
	sra	%3 (%4)
	rr	%5 (%6)
	djnz	%1
} by {
	ld	b,%2
	ld	e,%3 (%4)
	ld	a,%5 (%6)
%1:
	sra	e
	rra
	djnz	%1
	ld	%3 (%4),e
	ld	%5 (%6),a
	; peephole z88dk-411h2
} if notUsed('a'), notUsed('e')
// notVolatile

replace restart {
	ld	b,%2
%1:
	sra	%3 (%4)
	rr	%5 (%6)
	djnz	%1
} by {
	ld	b,%2
	ld	l,%3 (%4)
	ld	a,%5 (%6)
%1:
	sra	l
	rra
	djnz	%1
	ld	%3 (%4),l
	ld	%5 (%6),a
	; peephole z88dk-411h3
} if notUsed('a'), notUsed('l')
// notVolatile

replace restart {
	ld	a,%1
%2:
	sra	%4
	rr	%5
	dec	a
	%3	NZ,%2
} by {
	ld	a,%5
	ld	%5,%1
%2:
	sra	%4
	rra
	dec	%5
	jp	NZ,%2
	ld	%5,a
	ld	a,#0x00
	; peephole z88dk-411i
}

replace restart {
	ld	a,%1
%2:
	srl	%4
	rr	%5
	dec	a
	%3	NZ,%2
} by {
	ld	a,%5
	ld	%5,%1
%2:
	srl	%4
	rra
	dec	%5
	jp	NZ,%2
	ld	%5,a
	ld	a,#0x00
	; peephole z88dk-411j
}

replace restart {
	ld	b,%1
%2:
	srl	%3
	rr	%4
	djnz	%2
} by {
	ld	b,%1
	ld	a,%4
%2:
	srl	%3
	rra
	djnz	%2
	ld	%4,a
	; peephole z88dk-411k
} if notUsed('a')

replace restart {
	ld	a,#0x08
%1:
	srl	h
	rr	l
	rr	d
	rr	e
	dec	a
	%2	NZ,%1
} by {
	ld	e,d
	ld	d,l
	ld	l,h
	ld	h,0
	ld	a,h
	; peephole z88dk-411l
}

replace restart {
	ld	a,#%5
	jp	%2
%1:
	sla	%6 (%7)
	rl	%8 (%9)
%2:
	dec	a
	%4	NZ,%1
} by {
	ld	b,#%5
	ld	c,%6 (%7)
	ld	a,%8 (%9)
	jp	%2
%1:
	sla	c
	rla
%2:
	djnz	%1
	ld	%6 (%7),c
	ld	%8 (%9),a
	ld	a,b
	; peephole z88dk-411m1
} if notUsed('bc')
// notVolatile

replace restart {
	ld	a,#%5
	jp	%2
%1:
	sla	%6 (%7)
	rl	%8 (%9)
%2:
	dec	a
	%4	NZ,%1
} by {
	ld	e,#%5
	ld	d,%6 (%7)
	ld	a,%8 (%9)
	jp	%2
%1:
	sla	d
	rla
%2:
	dec	e
	jp	NZ,%1
	ld	%6 (%7),d
	ld	%8 (%9),a
	ld	a,e
	; peephole z88dk-411m2
} if notUsed('de')
// notVolatile

replace restart {
	ld	a,#%5
	jp	%2
%1:
	sla	%6 (%7)
	rl	%8 (%9)
%2:
	dec	a
	%4	NZ,%1
} by {
	ld	l,#%5
	ld	h,%6 (%7)
	ld	a,%8 (%9)
	jp	%2
%1:
	sla	h
	rla
%2:
	dec	l
	jp	NZ,%1
	ld	%6 (%7),h
	ld	%8 (%9),a
	ld	a,l
	; peephole z88dk-411m3
} if notUsed('hl')
// notVolatile

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7 (%8),%9
	ld	%10 (%11),%12
	ld	a,%13
%15:
	sla	%1 (%2)
	rl	%4 (%5)
	rl	%7 (%8)
	rl	%10 (%11)
	dec	a
	%14	NZ,%15
} by {
	ld	a,%13
%15:
	sla	%3
	rl	%6
	rl	%9
	rl	%12
	dec	a
	jp	NZ,%15
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7 (%8),%9
	ld	%10 (%11),%12
	; peephole z88dk-411n
} if notUsed(%3), notUsed(%6), notUsed(%9), notUsed(%12)
// notVolatile

replace restart {
	ld	%1 (%2),#0x%3
	ld	%4 (%5),#0x%6
	ld	%7 (%8),#0x%9
	ld	%10 (%11),#0x%12
	inc	b
	jp	%13
%14:
	sla	%1 (%2)
	rl	%4 (%5)
	rl	%7 (%8)
	rl	%10 (%11)
%13:
	djnz	%14
} by {
	ld	hl,#0x%6%3
	ld	%7 (%8),#0x%9
	ld	%10 (%11),#0x%12
	inc	b
	jp	%13
%14:
	add	hl,hl
	rl	%7 (%8)
	rl	%10 (%11)
%13:
	djnz	%14
	ld	%1 (%2),l
	ld	%4 (%5),h
	; peephole z88dk-411o1
} if notUsed('hl')

replace restart {
	ld	%1 (%2),#0x%3
	ld	%4 (%5),#0x%6
	ld	%7 (%8),#0x%9
	ld	%10 (%11),#0x%12
	inc	b
	jp	%13
%14:
	sla	%1 (%2)
	rl	%4 (%5)
	rl	%7 (%8)
	rl	%10 (%11)
%13:
	djnz	%14
} by {
	ld	de,#0x%6%3
	ld	%7 (%8),#0x%9
	ld	%10 (%11),#0x%12
	inc	b
	jp	%13
%14:
	sla	e
	rl	d
	rl	%7 (%8)
	rl	%10 (%11)
%13:
	djnz	%14
	ld	%1 (%2),e
	ld	%4 (%5),d
	; peephole z88dk-411o2
} if notUsed('de')

replace restart {
	ld	%7 (%8),#0x%9
	ld	%10 (%11),#0x%12
	inc	b
	jp	%13
%14:
	add	hl,hl
	rl	%7 (%8)
	rl	%10 (%11)
%13:
	djnz	%14
} by {
	ld	de,#0x%12%9
	inc	b
	jp	%13
%14:
	add	hl,hl
	rl	e
	rl	d
%13:
	djnz	%14
	ld	%7 (%8),e
	ld	%10 (%11),d
	; peephole z88dk-411o3
} if notUsed('de')

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7 (%8),%9
	ld	%10 (%11),%12
	ld	a,%13
%14:
	srl	%10 (%11)
	rr	%7 (%8)
	rr	%4 (%5)
	rr	%1 (%2)
	dec	a
	%15	NZ,%14
} by {
	ld	a,%13
%14:
	srl	%12
	rr	%9
	rr	%6
	rr	%3
	dec	a
	jp	NZ,%14
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7 (%8),%9
	ld	%10 (%11),%12
	; peephole z88dk-411p1
}

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7 (%8),%9
	ld	%10 (%11),%12
	ld	b,%13
%14:
	srl	%10 (%11)
	rr	%7 (%8)
	rr	%4 (%5)
	rr	%1 (%2)
	djnz	%14
} by {
	ld	b,%13
%14:
	srl	%12
	rr	%9
	rr	%6
	rr	%3
	djnz	,%14
	ld	%1 (%2),%3
	ld	%4 (%5),%6
	ld	%7 (%8),%9
	ld	%10 (%11),%12
	; peephole z88dk-411p2
}

replace restart {
	ld	a,#0x18
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x18
	ld	%6,%3
	xor	a,a
	ld	%3,a
	ld	%4,a
	ld	%5,a
	; peephole z88dk-411q1
}

replace restart {
	ld	b,#0x18
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	djnz	%1
} by {
	ld	%6,%3
	ld	b,#0x00
	ld	%3,b
	ld	%4,b
	ld	%5,b
	; peephole z88dk-411q2
}

replace restart {
	ld	de,%4
	ld	hl,%5
	ld	%6 (%7),#0x%8
	ld	%9 (%10),#0x%11
	ld	%12 (%13),#0x%14
	ld	%15 (%16),#0x%17
	inc	c
	jp	%3
%1:
	sla	%6 (%7)
	rl	%9 (%10)
	rl	%12 (%13)
	rl	%15 (%16)
%3:
	dec	c
	%2	NZ,%1
} by {
	ld	hl,#0x%11%8
	ld	de,#0x%17%14
	inc	c
	jp	%3
%1:
	add	hl,hl
	rl	e
	rl	d
%3:
	dec	c
	jp	NZ,%1
	ld	%6 (%7),l
	ld	%9 (%10),h
	ld	%12 (%13),e
	ld	%15 (%16),d
	ld	de,%4
	ld	hl,%5
	; peephole z88dk-411r1
}

replace restart {
	ld	de,%4
	ld	hl,%5
	ld	%6 (%7),#0x%8
	ld	%9 (%10),#0x%11
	ld	%12 (%13),#0x%14
	ld	%15 (%16),#0x%17
	inc	b
	jp	%3
%1:
	sla	%6 (%7)
	rl	%9 (%10)
	rl	%12 (%13)
	rl	%15 (%16)
%3:
	djnz	%1
} by {
	ld	hl,#0x%11%8
	ld	de,#0x%17%14
	inc	b
	jp	%3
%1:
	add	hl,hl
	rl	e
	rl	d
%3:
	djnz	%1
	ld	%6 (%7),l
	ld	%9 (%10),h
	ld	%12 (%13),e
	ld	%15 (%16),d
	ld	de,%4
	ld	hl,%5
	; peephole z88dk-411r2
}

replace restart {
	ld	a,#0x08
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x08
	ld	%6,%5
	ld	%5,%4
	ld	%4,%3
	xor	a,a
	ld	%3,a
	; peephole z88dk-411s
}

replace restart {
	ld	a,#0x07
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	dec	a
	%2	NZ,%1
} by {
	xor	a,a
	rl	%6
	rl	%5
	rl	%4
	rl	%3
	ld	%6,%5
	ld	%5,%4
	ld	%4,%3
	ld	d,a
	rl	d
	; peephole z88dk-411t
}

replace restart {
	ld	a,#0x18
%1:
	sla	%3
	rl	%4
	rl	%5
	rl	%6
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x18
	ld	%6,%3
	xor	a,a
	ld	%5,a
	ld	%4,a
	ld	%3,a
	; peephole z88dk-411u1
}

replace restart {
	ld	a,#0x18
	ld	%7,%8
%1:
	sla	%3
	rl	%4
	rl	%5
	rl	%6
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x18
	ld	%7,%8
	ld	%6,%3
	xor	a,a
	ld	%5,a
	ld	%4,a
	ld	%3,a
	; peephole z88dk-411u2
} if notSame(%7 'a')

replace restart {
	ld	a,#0x10
%1:
	sla	%3
	rl	%4
	adc	hl,hl
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x10
	ld	l,%3
	ld	h,%4
	xor	a,a
	ld	%4,a
	ld	%3,a
	; peephole z88dk-411v1
}

replace restart {
	ld	a,#0x10
	ld	%7,%8
%1:
	sla	%3
	rl	%4
	adc	hl,hl
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x10
	ld	%7,%8
	ld	l,%3
	ld	h,%4
	xor	a,a
	ld	%4,a
	ld	%3,a
	; peephole z88dk-411v2
} if notSame(%7 'a')

replace restart {
	ld	a,#0x10
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x10
	ld	%5,%3
	ld	%6,%4
	xor	a,a
	ld	%4,a
	ld	%3,a
	; peephole z88dk-411w1
}

replace restart {
	ld	a,#0x10
	ld	%7,%8
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	dec	a
	%2	NZ,%1
} by {
	ld	a,#0x10
	ld	%7,%8
	ld	%5,%3
	ld	%6,%4
	xor	a,a
	ld	%4,a
	ld	%3,a
	; peephole z88dk-411w2
} if notSame(%7 'a')

replace restart {
	ld	b,#0x10
%1:
	sla	%2
	rl	%3
	adc	hl, hl
	djnz	%1
} by {
	ld	h,%3
	ld	l,%2
	ld	b,#0x00
	ld	%3,#0x00
	ld	%2,#0x00
	; peephole z88dk-411x1
}

replace restart {
	ld	b,#0x10
	ld	%7,%8
%1:
	sla	%2
	rl	%3
	adc	hl, hl
	djnz	%1
} by {
	ld	b,#0x10
	ld	%7,%8
	ld	h,%3
	ld	l,%2
	ld	b,#0x00
	ld	%3,#0x00
	ld	%2,#0x00
	; peephole z88dk-411x2
} if operandsNotRelated(%7 'b')

replace restart {
	ld	b,#0x18
%2:
	sla	%3 (%4)
	rl	%5 (%6)
	rl	%7 (%8)
	rl	%9 (%10)
	djnz	%2
} by {
	ld	a,%3 (%4)
	ld	%9 (%10),a
	xor	a,a
	ld	b,a
	ld	%7 (%8),a
	ld	%5 (%6),a
	ld	%3 (%4),a
	; peephole z88dk-411y
} if notUsed('a')

replace restart {
	ld	b,#0x10
%2:
	sla	%3 (%4)
	rl	%5 (%6)
	rl	%7 (%8)
	rl	%9 (%10)
	djnz	%2
} by {
	ld	a,%5 (%6)
	ld	%9 (%10),a
	ld	a,%3 (%4)
	ld	%7 (%8),a
	xor	a,a
	ld	b,a
	ld	%5 (%6),a
	ld	%3 (%4),a
	; peephole z88dk-411z
} if notUsed('a')

replace restart {
	ld	b,#0x09
%1:
	srl	%2
	rr	%3
	rr	%4
	rr	%5
	djnz	%1
} by {
	srl	%2
	rr	%3
	rr	%4
	ld	%5,%4
	ld	%4,%3
	ld	%3,%2
	ld	b,#0x00
	ld	%2,#0x00
	; peephole z88dk-411aa
}

replace restart {
	ld	a,#0x09
%1:
	srl	%3
	rr	%4
	rr	%5
	rr	%6
	dec	a
	%2	NZ,%1
} by {
	srl	%3
	rr	%4
	rr	%5
	ld	%6,%5
	ld	%5,%4
	ld	%4,%3
	xor	a,a
	ld	%3,a
	; peephole z88dk-411ab
}

replace restart {
	ld	a,#0x09
%1:
	sla	%3
	rl	%4
	adc	hl, hl
	dec	a
	%2	NZ,%1
} by {
	ld	h,l
	ld	l,%4
	ld	%4,%3
	xor	a,a
	sla	%4
	adc	hl,hl
	ld	%3,a
	; peephole z88dk-411ac
}

replace restart {
	ld	a,#0x09
%1:
	add	hl, hl
	rl	%3
	rl	%4
	dec	a
	%2	NZ,%1
} by {
	ld	%4,%3
	ld	%3,h
	ld	h,l
	xor	a,a
	sla	h
	rl	%3
	rl	%4
	ld	l,a
	; peephole z88dk-411ad
}

replace restart {
	ld	a,#0x09
%1:
	sla	%3
	rl	%4
	rl	%5
	rl	%6
	dec	a
	%2	NZ,%1
} by {
	ld	%6,%5
	ld	%5,%4
	ld	%4,%3
	xor	a,a
	sla	%4
	rl	%5
	rl	%6
	ld	%3,a
	; peephole z88dk-411ae
}

replace restart {
	jp	%1
%2:
	sla	e
	rl	d
%1:
	dec	l
	%3	NZ,%2
} by {
	ex	de,hl
	jp	%1
%2:
	add	hl,hl
%1:
	dec	e
	%3	NZ,%2
	ex	de,hl
	; peephole z88dk-411af
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,#%1
%2:
	sla	c
	rl	b
	rl	e
	rl	d
	dec	a
	%3	NZ,%2
} by {
	ld	a,#%1
%2:
	add	hl,hl
	rl	e
	rl	d
	dec	a
	%3	NZ,%2
	ld	c,l
	ld	b,h
	; peephole z88dk-411ag
} if notUsed('hl')

replace restart {
	jp	%1
%2:
	sla	e
	rl	d
%1:
	dec	a
	%3	NZ,%2
} by {
	ex	de,hl
	jp	%1
%2:
	add	hl,hl
%1:
	dec	a
	%3	NZ,%2
	ex	de,hl
	; peephole z88dk-411ah
} if notUsed('hl')

replace restart {
	jp	%1
%2:
	ld	hl,(#%3)
	add	hl,hl
	ld	(#%3),hl
%1:
	djnz	%2
} by {
	ld	hl,(#%3)
	jp	%1
%2:
	add	hl,hl
%1:
	djnz	%2
	ld	(#%3),hl
	; peephole z88dk-411ai
} if notVolatile(%3)

replace restart {
	jp	%1
%2:
	ld	hl,#%3 + 1
	srl	(hl)
	dec	hl
	rr	(hl)
%1:
	djnz	%2
} by {
	ld	hl,(#%3)
	jp	%1
%2:
	srl	h
	rr	l
%1:
	djnz	%2
	ld	(#%3),hl
	ld	hl,#%3
	; peephole z88dk-411aj
} if notVolatile(%3)

replace restart {
	ld	c,l
	ld	b,h
%1:
	sla	c
	rl	b
	rl	e
	rl	d
	dec	a
	%2	NZ,%1
} by {
	ld	b,a
%1:
	add	hl,hl
	rl	e
	rl	d
	djnz	%1
	ld	a,b
	ld	c,l
	ld	b,h
	; peephole z88dk-411ak
} if notUsed('hl')

replace restart {
	ld	a,#%1
%2:
	add	hl,hl
	rl	e
	rl	d
	dec	a
	%3	NZ,%2
} by {
	ld	b,#%1
%2:
	add	hl,hl
	rl	e
	rl	d
	djnz	%2
	ld	a,b
	; peephole z88dk-411al
} if notUsed('b')

replace restart {
	ld	c,l
	ld	b,h
	ld	l,e
	ld	h,d
	ld	a,#%1
%2:
	sla	c
	rl	b
	adc	hl,hl
	dec	a
	%3	NZ,%2
} by {
	ld	b,#%1
%2:
	add	hl,hl
	rl	e
	rl	d
	djnz	%2
	ld	a,b
	ld	c,l
	ld	b,h
	ex	de,hl
	; peephole z88dk-411am
} if notUsed('de')

replace restart {
	ld	a,#%1
	ex	de,hl
	ld	c,e
	ld	b,d
%2:
	sla	c
	rl	b
	adc	hl,hl
	dec	a
	%3	NZ,%2
} by {
	ld	b,#%1
%2:
	add	hl,hl
	rl	e
	rl	d
	djnz	%2
	ld	a,b
	ex	de,hl
	ld	c,e
	ld	b,d
	; peephole z88dk-411an
} if notUsed('de')





replace restart {
	ld	%1,(hl)
	ld	a,%1
} by {
	ld	a,(hl)
	ld	%1,a
	; peephole z88dk-412
} if notSame(%1 'a')

replace restart {
	pop	%1
	ld	(%2),%1
} by {
	pop	hl
	ld	(%2),hl
	; peephole z88dk-413a
} if notUsed(%1), notUsed('hl'), notSame(%1 'hl')

replace restart {
	pop	%1
	ld	(%2 + %3),%1
} by {
	pop	hl
	ld	(%2 + %3),hl
	; peephole z88dk-413b
} if notUsed(%1), notUsed('hl'), notSame(%1 'hl')

replace restart {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	ld	(%5),bc
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(%5),hl
	; peephole z88dk-413c
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	ld	(%5 + %6),bc
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(%5 + %6),hl
	; peephole z88dk-413d
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	e,%1 (%2)
	ld	d,%3 (%4)
	ld	(%5),de
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(%5),hl
	; peephole z88dk-413e
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	e,%1 (%2)
	ld	d,%3 (%4)
	ld	(%5 + %6),de
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(%5 + %6),hl
	; peephole z88dk-413f
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	%2 (%1),%5
	ld	%3 (%1),%4
	ld	%6,%2 (%1)
} by {
	ld	%2 (%1),%5
	ld	%3 (%1),%4
	ld	%6,%5
	; peephole z88dk-414a
} if notSame(%2 %3)
// notVolatile

replace restart {
	ld	%4,%5
	ld	%1 (%2),%3
	ld	%5,%4
} by {
	ld	%4,%5
	ld	%1 (%2),%3
	; peephole z88dk-414b
} if canAssign(%4 '(hl)'), canAssign(%5 '(hl)')

replace restart {
	ld	%1 (%2),%3
	ld	%5,%6
	add	a,%7
	ld	%1 (%2),%4
} by {
	ld	%5,%6
	add	a,%7
	ld	%1 (%2),%4
	; peephole z88dk-414c
} if canAssign(%5 '(hl)')
// notVolatile

replace restart {
	ld	%1 (%2),%3
	ld	%4 (%2),%6
	ld	a,%7
	or	a,%1 (%2)
} by {
	ld	%1 (%2),%3
	ld	%4 (%2),%6
	ld	a,%7
	or	a,%3
	; peephole z88dk-414d
} if notSame(%1 %4)
// notVolatile

replace restart {
	ld	%1,%2 (%3)
	ld	%5,%6 (%3)
	ld	%4,%1
} by {
	ld	%4,%2 (%3)
	ld	%5,%6 (%3)
	; peephole z88dk-414e
} if notUsed(%1), canAssign(%4 '(hl)'), notSame(%4 %5), notSame(%1 %5)

replace restart {
	ld	%1,%2 (%3)
	ld	%5,%6 (%3)
	ld	%7,%8 (%3)
	ld	%4,%1
} by {
	ld	%4,%2 (%3)
	ld	%5,%6 (%3)
	ld	%7,%8 (%3)
	; peephole z88dk-414f
} if notUsed(%1), canAssign(%4 '(hl)'), notSame(%4 %5), notSame(%4 %7), notSame(%1 %5), notSame(%1 %7)

replace restart {
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	sla	%1 (%2)
	rl	%3 (%4)
} by {
	sla	%5
	rl	%6
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	; peephole z88dk-414g1
} if notUsed(%5), notUsed(%6), canAssign(%5 '(hl)'), canAssign(%6 '(hl)')
// notVolatile

replace restart {
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	sla	%1 (%2)
	rl	%3 (%4)
} by {
	ld	l,%5
	ld	h,%6
	add	hl,hl
	ld	%1 (%2),l
	ld	%3 (%4),h
	; peephole z88dk-414g2
} if notUsed('hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	; peephole z88dk-414h1
} if operandsNotRelated(%5 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	%7
	; peephole z88dk-414h1a
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	dec	%7
	; peephole z88dk-414h1b
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	dec	hl
	; peephole z88dk-414h2
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%6 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	inc	%7
	dec	hl
	; peephole z88dk-414h3a
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%6 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	dec	%7
	dec	hl
	; peephole z88dk-414h3b
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%6 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	; peephole z88dk-414h4  INCORRECT IF POINTER POINTS TO SELF
}
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	%7
	; peephole z88dk-414h4a  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	dec	%7
	; peephole z88dk-414h4b  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	dec	hl
	; peephole z88dk-414h5  INCORRECT IF POINTER POINTS TO SELF
}
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	inc	%7
	dec	hl
	; peephole z88dk-414h5a  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	dec	%7
	dec	hl
	; peephole z88dk-414h5b  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	; peephole z88dk-414i1
} if operandsNotRelated(%5 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	%7
	; peephole z88dk-414i1a
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	dec	%7
	; peephole z88dk-414i1b
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	dec	hl
	; peephole z88dk-414i2
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%6 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	inc	%7
	dec	hl
	; peephole z88dk-414i3a
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%6 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	%5,(hl)
	inc	hl
	ld	%6,(hl)
	dec	%7
	dec	hl
	; peephole z88dk-414i3b
} if operandsNotRelated(%5 'hl'), operandsNotRelated(%6 'hl'), operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	; peephole z88dk-414i4  INCORRECT IF POINTER POINTS TO SELF
}
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	%7
	; peephole z88dk-414ia  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	dec	%7
	; peephole z88dk-414i4b  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	dec	hl
	; peephole z88dk-414i5  INCORRECT IF POINTER POINTS TO SELF
}
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	inc	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	inc	%7
	dec	hl
	; peephole z88dk-414i5a  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	dec	%7
	ld	l,%1 (%2)
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	(hl),%5
	inc	hl
	ld	(hl),%6
	dec	%7
	dec	hl
	; peephole z88dk-414i5b  INCORRECT IF POINTER POINTS TO SELF
} if operandsNotRelated(%7 'hl')
// notVolatile

replace restart {
	ld	%1,%2 (%3)
	ld	%4 (%3),%5
	ld	%1,%2 (%3)
} by {
	ld	%1,%2 (%3)
	ld	%4 (%3),%5
	; peephole z88dk-414j
} if notSame(%2 %4)
// notVolatile

replace restart {
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	ld	%9,%10
	ld	%7,%1 (%2)
	ld	%8,%3 (%4)
} by {
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	ld	%9,%10
	ld	%7,%5
	ld	%8,%6
	; peephole z88dk-414k1
} if operandsNotRelated(%9 %5), operandsNotRelated(%9 %6)

replace restart {
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	ld	%9,%10
	ld	%7,%1 (%2)
	ld	%8,%3 (%4)
} by {
	ld	%1 (%2),%5
	ld	%3 (%4),%6
	ld	%7,%5
	ld	%8,%6
	ld	%9,%10
	; peephole z88dk-414k2
} if operandsNotRelated(%9 %7), operandsNotRelated(%9 %8), operandsNotRelated(%10 %7), operandsNotRelated(%10 %8)

replace restart {
	ld	%1 (%2),a
	ld	a,%4 (%5)
	adc	a,%6 (%7)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%3,a
	ld	a,%4 (%5)
	adc	a,%6 (%7)
	; peephole z88dk-414l1
}

replace restart {
	ld	%1 (%2),a
	ld	a,%4 (%5)
	add	a,%6 (%7)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%3,a
	ld	a,%4 (%5)
	add	a,%6 (%7)
	; peephole z88dk-414l2
}

replace restart {
	ld	%1 (%2),a
	ld	a,%4 (%5)
	sbc	a,%6 (%7)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%3,a
	ld	a,%4 (%5)
	sbc	a,%6 (%7)
	; peephole z88dk-414l3
}

replace restart {
	ld	%1 (%2),a
	ld	a,%4 (%5)
	sub	a,%6 (%7)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%3,a
	ld	a,%4 (%5)
	sub	a,%6 (%7)
	; peephole z88dk-414l4
} if operandsNotRelated(%3 'a')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, #<(%2)
	ld	c,a
	inc	hl
	ld	a,(hl)
	sbc	a, #>(%2)
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	bc,#%2
	xor	a,a
	sbc	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-415a
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	a,l
	sub	a, #<(%1)
	ld	c,a
	ld	a,h
	sbc	a, #>(%1)
	ld	b,a
	ld	hl,%2
	push	hl
	push	bc
} by {
	ld	bc,#%1
	xor	a,a
	sbc	hl,bc
	ld	bc,%2
	push	bc
	push	hl
	; peephole z88dk-415b
} if notUsed('a'), notUsed('bc'), notUsed('hl')

replace restart {
	ld	a,#0x%1
	sub	a, c
	ld	l,a
	ld	a,#0x%2
	sbc	a, b
	ld	h,a
} by {
	ld	hl,#0x%2%1
	xor	a,a
	sbc	hl,bc
	ld	a,h
	; peephole z88dk-415c
}

replace restart {
	ld	a,e
	ld	hl,#%1
	sub	a,(hl)
	ld	e,a
	ld	a,d
	inc	hl
	sbc	a,(hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	ex	de,hl
	xor	a,a
	sbc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-415d1
} if notUsed('hl')

replace restart {
	ld	a,e
	ld	hl,#%1 + %2
	sub	a,(hl)
	ld	e,a
	ld	a,d
	inc	hl
	sbc	a,(hl)
	ld	d,a
} by {
	ld	hl,(#%1 + %2)
	ex	de,hl
	xor	a,a
	sbc	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-415d2
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a, c
	ld	c,a
	inc	hl
	ld	a,(hl)
	sbc	a, b
	ld	b,a
} by {
	ld	hl,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-415e1
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	sub	a, c
	ld	c,a
	inc	hl
	ld	a,(hl)
	sbc	a, b
	ld	b,a
} by {
	ld	hl,(#%1 + %2)
	xor	a,a
	sbc	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-415e2
} if notUsed('hl')

replace restart {
	ld	a,c
	ld	hl,#%1 + 1
	sub	a, e
	dec	hl
	ld	(hl),a
	ld	a,b
	sbc	a, d
	inc	hl
	ld	(hl),a
} by {
	ld	l,c
	ld	h,b
	xor	a,a
	sbc	hl,de
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-415f
}

replace restart {
	ld	a,e
	sub	a,c
	ld	l,a
	ld	a,d
	sbc	a,b
	ld	h,a
} by {
	ld	l,e
	ld	h,d
	xor	a,a
	sbc	hl,bc
	; peephole z88dk-415g
} if notUsed('a')








replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	push	hl
	push	bc
} by {
	ld	bc,%1
	push	bc
	push	hl
	; peephole z88dk-416a
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	bc, (%1)
	push	de
	push	bc
} by {
	push	de
	ld	hl,(%1)
	push	hl
	; peephole z88dk-416b
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	bc,(%1)
	ld	de,%2
	push	de
} by {
	ld	de,%2
	ld	bc,(%1)
	push	de
	; peephole z88dk-416c
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	push	hl
	push	de
	push	bc
} by {
	ld	bc,#%1
	push	bc
	push	de
	push	hl
	; peephole z88dk-416d
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	xor	a,a
	push	af
	inc	sp
	push	bc
} by {
	ld	c,l
	ld	b,h
	xor	a,a
	push	af
	inc	sp
	push	hl
	; peephole z88dk-416e1
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,%1
	push	af
	inc	sp
	push	de
	push	bc
} by {
	ld	c,l
	ld	b,h
	ld	a,%1
	push	af
	inc	sp
	push	de
	push	hl
	; peephole z88dk-416e2
}

replace restart {
	ex	de,hl
	xor	a,a
	push	af
	inc	sp
	push	bc
	push	de
} by {
	xor	a,a
	push	af
	inc	sp
	push	bc
	push	hl
	; peephole z88dk-416f1
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	ld	a,%1
	push	af
	inc	sp
	push	bc
	push	de
} by {
	ld	a,%1
	push	af
	inc	sp
	push	bc
	push	hl
	; peephole z88dk-416f2
} if notUsed('de'), notUsed('hl'), operandsNotRelated(%1 'de'), operandsNotRelated(%1 'hl')

replace restart {
	ld	c,l
	ld	b,h
	ld	de,(%1)
	ld	a,e
	ld	(bc),a
	inc	bc
	ld	a,d
	ld	(bc),a
} by {
	ld	de,(%1)
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	a,d
	ld	c,l
	ld	b,h
	dec	hl
	; peephole z88dk-417a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	de,(%1 + %2)
	ld	a,e
	ld	(bc),a
	inc	bc
	ld	a,d
	ld	(bc),a
} by {
	ld	de,(%1 + %2)
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	a,d
	ld	c,l
	ld	b,h
	dec	hl
	; peephole z88dk-417b
}

replace restart {
	ld	e,l
	ld	d,h
	ld	(hl),a
	push	de
} by {
	ld	(hl),a
	push	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-418a
}

replace restart {
	ld	e,l
	ld	d,h
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	push	de
} by {
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	dec	hl
	push	hl
	; peephole z88dk-418b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	e,l
	ld	d,h
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	push	bc
	push	de
} by {
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	dec	hl
	push	bc
	push	hl
	; peephole z88dk-418c
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	e,c
	ld	d,b
	push	bc
	push	de
} by {
	push	bc
	push	bc
	ld	e,c
	ld	d,b
	; peephole z88dk-418d
}

replace restart {
	ld	e,l
	ld	d,h
	push	bc
	push	de
} by {
	push	bc
	push	hl
	ld	e,l
	ld	d,h
	; peephole z88dk-418e
}

replace restart {
	ld	e,c
	ld	d,b
	push	de
} by {
	push	bc
	ld	e,c
	ld	d,b
	; peephole z88dk-418f
}

replace restart {
	ld	c,e
	ld	b,d
	push	bc
} by {
	push	de
	ld	c,e
	ld	b,d
	; peephole z88dk-418g
}

replace restart {
	ld	e, c
	ld	d, b
	push	bc
	ld	hl,%1
	push	hl
	ld	hl,%2
	push	hl
	push	de
} by {
	push	bc
	ld	hl,%1
	push	hl
	ld	hl,%2
	push	hl
	push	bc
	ld	e,c
	ld	d,b
	; peephole z88dk-418h
}

replace restart {
	ld	hl,#%1 + 1
	push	bc
	ld	b,(hl)
	dec	hl
	ld	c,(hl)
} by {
	push	bc
	ld	bc,(#%1)
	ld	hl,#%1
	; peephole z88dk-418i
}

replace restart {
	ex	de,hl
	pop	bc
	ld	a,d
	or	a,e
} by {
	pop	bc
	ld	a,h
	or	a,l
	ex	de,hl
	; peephole z88dk-418j
}

replace restart {
	ex	de,hl
	pop	bc
	xor	a, a
	cp	a, e
	sbc	a, d
} by {
	pop	bc
	xor	a,a
	cp	a,l
	sbc	a,h
	ex	de,hl
	; peephole z88dk-418k
}

replace restart {
	ld	e,c
	ld	d,b
	push	hl
	push	de
} by {
	push	hl
	push	bc
	ld	e,c
	ld	d,b
	; peephole z88dk-418l
}

replace restart {
	ld	c,d
	ld	b,e
	push	de
	push	af
	inc	sp
	push	bc
} by {
	push	de
	push	af
	inc	sp
	push	de
	ld	c,d
	ld	b,e
	; peephole z88dk-418m
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	ld	de,%2
	push	de
	push	bc
	push	hl
} by {
	ld	bc,%1
	ld	de,%2
	push	de
	push	hl
	push	bc
	; peephole z88dk-418n
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	push	bc
} by {
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	dec	hl
	push	hl
	; peephole z88dk-418o
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	push	bc
} by {
	push	hl
	ld	hl,%1
	; peephole z88dk-418p1
} if notUsed('bc')

replace restart {
	ld	c,e
	ld	b,d
	ld	hl,%1
	push	bc
} by {
	push	de
	ld	hl,%1
	; peephole z88dk-418p2
} if notUsed('bc')

replace restart {
	ex	de,hl
	ld	hl,%1
	push	de
} by {
	push	hl
	ld	hl,%1
	; peephole z88dk-418q
} if notUsed('de')

replace restart {
	ld	c,e
	ld	b,d
	push	de
	push	bc
} by {
	push	de
	push	de
	ld	c,e
	ld	b,d
	; peephole z88dk-418r
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	push	de
	push	bc
} by {
	push	de
	push	hl
	ld	hl,%1
	; peephole z88dk-418s
} if notUsed('bc')

replace restart {
	ld	e,c
	ld	d,b
	ld	hl,%1
	push	bc
	push	de
} by {
	ld	hl,%1
	push	bc
	push	bc
	ld	e,c
	ld	d,b
	; peephole z88dk-418t
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	push	bc
} by {
	push	hl
	ld	c,l
	ld	b,h
	ld	hl,%1
	; peephole z88dk-418u
}

replace restart {
	ld	hl,%1
	ld	%3,%2
	push	%3
} by {
	ld	%3,%2
	push	%3
	ld	hl,%1
	; peephole z88dk-418v
} if notSame(%3 'hl')

replace restart {
	push	af
	ld	hl,%1
	ex	(sp), hl
} by {
	ld	hl,%1
	push	hl
	; peephole z88dk-418w
} if notUsed('hl')

replacer restart {
	ld	c,e
	ld	b,d
	push	hl
	push	bc
} by {
	push	hl
	push	de
	ld	c,e
	ld	b,d
	; peephole z88dk-418x
}

replace restart {
	ex	(sp), hl
	pop	hl
	push	hl
} by {
	pop	bc
	push	hl
	; peephole z88dk-418y1
} if notUsed('bc')

replace restart {
	ex	(sp), hl
	pop	hl
	push	hl
} by {
	pop	de
	push	hl
	; peephole z88dk-418y2
} if notUsed('de')

replace restart {
	ld	c,e
	ld	b,d
	push	de
	ld	hl,%1
	push	hl
	ld	hl,%2
	push	hl
	push	bc
} by {
	push	de
	ld	hl,%1
	push	hl
	ld	hl,%2
	push	hl
	push	de
	; peephole z88dk-418z
} if notUsed('bc')

replace restart {
	ld	c,l
	ld	b,h
	pop	hl
	push	hl
	push	bc
	push	hl
} by {
	pop	bc
	push	bc
	push	hl
	push	bc
	; peephole z88dk-418aa
} if notUsed('bc'), notUsed('hl')

replace restart {
	ex	de,hl
	ld	hl,%1
	push	hl
	push	de
} by {
	ld	de,%1
	push	de
	push	hl
	; peephole z88dk-418ab
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	e,c
	ld	d,b
	sla	e
	rl	d
} by {
	ld	l,c
	ld	h,b
	add	hl,hl
	ex	de,hl
	; peephole z88dk-419a
} if notUsed('hl')

replace restart {
	ld	e,c
	ld	d,b
	sla	e
	rl	d
} by {
	ld	e,c
	ld	d,b
	ex	de,hl
	add	hl,hl
	ex	de,hl
	; peephole z88dk-419b
}

replace restart {
	cp	a,a
	sbc	hl,%1
} by {
	xor	a,a
	sbc	hl,%1
	; peephole z88dk-420a
} if notUsed('a')

replace restart {
	ld	c,l
	ld	b,h
	ld	a,%1 (%2)
	add	a,c
	ld	c,a
	ld	a,%3 (%4)
	adc	a,b
	ld	b,a
} by {
	ld	a,%1 (%2)
	add	a,l
	ld	c,a
	ld	a,%3 (%4)
	adc	a,h
	ld	b,a
	; peephole z88dk-420b
}

replace restart {
	ld	%1,l
	ld	a,h
	sla	%1
	rla
} by {
	add	hl,hl
	ld	%1,l
	ld	a,h
	; peephole z88dk-421a
} if notUsed('hl')

replace restart {
	ld	bc,(%1)
	sla	c
	rl	b
} by {
	ld	hl,(%1)
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-421b1
} if notUsed('hl')

replace restart {
	ld	bc,(%1 + %2)
	sla	c
	rl	b
} by {
	ld	hl,(%1 + %2)
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-421b2
} if notUsed('hl')

replace restart {
	ld	de,(%1)
	sla	e
	rl	d
} by {
	ld	hl,(%1)
	add	hl,hl
	ld	e,l
	ld	d,h
	; peephole z88dk-421c1
} if notUsed('hl')

replace restart {
	ld	de,(%1 + %2)
	sla	e
	rl	d
} by {
	ld	hl,(%1 + %2)
	add	hl,hl
	ld	e,l
	ld	d,h
	; peephole z88dk-421c2
} if notUsed('hl')

replace restart {
	ld	b,(hl)
	dec	hl
	ld	c,(hl)
	sla	c
	rl	b
	sla	c
	rl	b
} by {
	ld	b,(hl)
	dec	hl
	ld	l,(hl)
	ld	h,b
	add	hl,hl
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-421d
} if notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	dec	bc
} by {
	dec	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-422a
} if notUsed('hl')

replace restart {
	dec	bc
	ld	l,c
	ld	h,b
} by {
	ld	l,c
	ld	h,b
	dec	hl
	; peephole z88dk-422b
} if notUsed('bc')

replace restart {
	ld	c,l
	ld	b,h
	inc	bc
} by {
	inc	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-422c
} if notUsed('hl')

replace restart {
	inc	bc
	ld	l,c
	ld	h,b
} by {
	ld	l,c
	ld	h,b
	inc	hl
	; peephole z88dk-422d
} if notUsed('bc')

replace restart {
	pop	bc
	push	bc
	ld	l,c
	ld	h,b
} by {
	pop	hl
	push	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-422e
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,%1
	cp	a,c
	ld	a,%2
	sbc	a,b
} by {
	ld	a,%1
	cp	a,l
	ld	a,%2
	sbc	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-423
} if notSame(%1 'b'), notSame(%1 'c'), notSame(%2 'b'), notSame(%2 'c')

replace restart {
	ld	%2,a
	ld	hl,#%1
	ld	(hl),%2
} by {
	ld	(#%1),a
	ld	%2,a
	; peephole z88dk-424a
} if notUsed('hl')

replace restart {
	ld	%2,a
	ld	hl,#%1
	ld	(hl),%2
} by {
	ld	hl,#%1
	ld	(hl),a
	ld	%2,a
	; peephole z88dk-424b
}

replace restart {
	ld	%2,a
	ld	hl,#%1 + %3
	ld	(hl),%2
} by {
	ld	(#%1 + %3),a
	ld	%2,a
	; peephole z88dk-424c
} if notUsed('hl')

replace restart {
	ld	%2,a
	ld	hl,#%1 + %3
	ld	(hl),%2
} by {
	ld	hl,#%1 + %3
	ld	(hl),a
	ld	%2,a
	; peephole z88dk-424d
}

replace restart {
	ld	%9,#%1
	or	a,%5
	jp	%4,%3
} by {
	or	a,%5
	jp	%4,%3
	ld	%9,#%1
	; peephole z88dk-425a1
} if notUsedFrom(%3 %9), operandsNotRelated(%5 %9), notSame(%9 'a')

replace restart {
	ld	%9,#%1 + %2
	or	a,%5
	jp	%4,%3
} by {
	or	a,%5
	jp	%4,%3
	ld	%9,#%1 + %2
	; peephole z88dk-425a2
} if notUsedFrom(%3 %9), operandsNotRelated(%5 %9), notSame(%9 'a')

replace restart {
	ld	%9,#%1
	jp	%2,%3
} by {
	jp	%2,%3
	ld	%9,#%1
	; peephole z88dk-425b1
} if notUsedFrom(%3 %9)

replace restart {
	ld	%9,#%1 + %4
	jp	%2,%3
} by {
	jp	%2,%3
	ld	%9,#%1 + %4
	; peephole z88dk-425b2
} if notUsedFrom(%3 %9)

replace restart {
	ld	%1,%2
	jp	%3,%4
} by {
	jp	%3,%4
	ld	%1,%2
	; peephole z88dk-425b3
} if canAssign(%1 '(hl)'), notUsedFrom(%4 %1)

replace restart {
	ld	%9,#%1
	ld	%7,%6
	or	a,%5
	jp	%4,%3
} by {
	ld	%7,%6
	or	a,%5
	jp	%4,%3
	ld	%9,#%1
	; peephole z88dk-425c1
} if notUsedFrom(%3 %9), operandsNotRelated(%5 %9), operandsNotRelated(%6 %9), operandsNotRelated(%7 %9), notSame(%9 'a')

replace restart {
	ld	%9,#%1 + %2
	ld	%7,%6
	or	a,%5
	jp	%4,%3
} by {
	ld	%7,%6
	or	a,%5
	jp	%4,%3
	ld	%9,#%1 + %2
	; peephole z88dk-425c2
} if notUsedFrom(%3 %9), operandsNotRelated(%5 %9), operandsNotRelated(%6 %9), operandsNotRelated(%7 %9), notSame(%9 'a')

replace restart {
	ld	%5,%6
	ld	a,%3
	or	a,%4
	jp	%1,%2
} by {
	ld	a,%3
	or	a,%4
	jp	%1,%2
	ld	%5,%6
	; peephole z88dk-425d1
} if canAssign(%5 '(hl)'), notUsedFrom(%2 %5), operandsNotRelated(%5 %3), operandsNotRelated(%5 %4), notSame(%5 'a'), notSame(%6 'a')

replace restart {
	ld	%5,%6
	or	a,%4
	jp	%1,%2
} by {
	or	a,%4
	jp	%1,%2
	ld	%5,%6
	; peephole z88dk-425d2
} if canAssign(%5 '(hl)'), notUsedFrom(%2 %5), operandsNotRelated(%5 %4), notSame(%5 'a'), notSame(%6 'a')

replace restart {
	ld	%7,%8
	ld	%5,%6
	or	a,%4
	jp	%1,%2
} by {
	ld	%5,%6
	or	a,%4
	jp	%1,%2
	ld	%7,%8
	; peephole z88dk-425d3
} if canAssign(%7 '(hl)'), notUsedFrom(%2 %7), operandsNotRelated(%7 %4), operandsNotRelated(%7 %6), operandsNotRelated(%7 %5), operandsNotRelated(%8 %5), notSame(%7 'a'), notSame(%8 'a')

replace restart {
	jp	%1,%2
	jp	%1,%3
} by {
	jp	%1,%2
	; peephole z88dk-425e
}

replace restart {
	ld	%1,%2
	bit	%3,%4
	jp	%5,%6
} by {
	bit	%3,%4
	jp	%5,%6
	ld	%1,%2
	; peephole z88dk-425f1
} if canAssign(%1 '(hl)'), operandsNotRelated(%1 %4), notUsedFrom(%6 %1)

replace restart {
	ld	%7,%8
	ld	%1,%2
	bit	%3,%4
	jp	%5,%6
} by {
	ld	%1,%2
	bit	%3,%4
	jp	%5,%6
	ld	%7,%8
	; peephole z88dk-425f2
} if canAssign(%7 '(hl)'), operandsNotRelated(%2 %7), operandsNotRelated(%1 %7), operandsNotRelated(%7 %4), operandsNotRelated(%8 %1), notUsedFrom(%6 %7)

replace restart {
	ld	e,c
	ld	d,b
	ld	hl,%1
	add	hl,de
} by {
	ld	e,c
	ld	d,b
	ld	hl,%1
	add	hl,bc
	; peephole z88dk-426a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,%1 (%2)
	ld	(bc),a
} by {
	ld	a,%1 (%2)
	ld	(hl),a
	ld	c,l
	ld	b,h
	; peephole z88dk-426b1
}

replace restart {
	ld	c,l
	ld	b,h
	inc	bc
	ld	a,%1 (%2)
	ld	(bc),a
} by {
	inc	hl
	ld	a,%1 (%2)
	ld	(hl),a
	ld	c,l
	ld	b,h
	dec	hl
	; peephole z88dk-426b2
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	ld	%3 (%4),a
	inc	hl
	ld	a,(hl)
} by {
	ld	hl,(#%1)
	ld	%3 (%4),l
	ld	a,h
	; peephole z88dk-427a
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	ld	%3 (%4),a
	inc	hl
	ld	a,(hl)
} by {
	ld	hl,(#%1 + %2)
	ld	a,l
	ld	%3 (%4),a
	ld	a,h
	; peephole z88dk-427b
} if notUsed('hl')

replace restart {
	inc	hl
	ld	b,(hl)
	dec	hl
	ld	c,(hl)
} by {
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	dec	hl
	; peephole z88dk-428
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	ld	(hl),a
	inc	hl
	ld	a,(#%1 + 1)
	ld	(hl),a
} by {
	ld	bc,(#%1)
	ld	hl,#%2
	ld	(hl),c
	inc	hl
	ld	(hl),b
	ld	a,b
	; peephole z88dk-429a
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	ld	(hl),a
	inc	hl
	ld	a,(#%1 + 1)
	ld	(hl),a
} by {
	ld	de,(#%1)
	ld	hl,#%2
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	a,d
	; peephole z88dk-429b
} if notUsed('de')

replace restart {
	%4	a,%1
	ld	a,%2
	or	a,%3
} by {
	ld	a,%2
	or	a,%3
	; peephole z88dk-430a
} if notSame('a' %2)
// notVolatile

replace restart {
	ld	%1,(hl)
	ld	a,#0x00
	or	a,%1
} by {
	ld	a,(hl)
	ld	%1,a
	or	a,a
	; peephole z88dk-430b
}

replace restart {
	or	a,#0x00
} by {
	or	a,a
	; peephole z88dk-430c
}

replace restart {
	and	a,#0x00
} by {
	xor	a,a
	; peephole z88dk-430d
}

replace restart {
	sra	%1
	rr	%2
	ld	a,%2
} by {
	ld	a,%2
	sra	%1
	rra
	ld	%2,a
	; peephole z88dk-431
}

replace restart {
	ld	bc,%1
	ld	e,c
	ld	d,b
	dec	de
	ld	%2,de
} by {
	ld	bc,%1
	dec	bc
	ld	%2,bc
	inc	bc
	; peephole z88dk-432a
} if notUsed('de')

replace restart {
	ld	bc,%1
	ld	e,c
	ld	d,b
	inc	de
	ld	%2,de
} by {
	ld	bc,%1
	inc	bc
	ld	%2,bc
	dec	bc
	; peephole z88dk-432b
} if notUsed('de')


replace restart {
	ld	e,c
	ld	d,b
	inc	de
	inc	de
	ld	a,%1
	ld	(de),a
	ld	e,c
	ld	d,b
} by {
	ld	e,c
	ld	d,b
	inc	de
	inc	de
	ld	a,%1
	ld	(de),a
	dec	de
	dec	de
	; peephole z88dk-433b
}

replace restart {
	ld	e,c
	ld	d,b
	inc	de
	ld	a,%1
	ld	(de),a
	ld	e,c
	ld	d,b
} by {
	ld	e,c
	ld	d,b
	inc	de
	ld	a,%1
	ld	(de),a
	dec	de
	; peephole z88dk-433c
}

replace restart {
	ld	l,c
	ld	h,b
	inc	hl
	inc	hl
	ld	a,(hl)
	ld	%1,a
	ld	l,c
	ld	h,b
} by {
	ld	l,c
	ld	h,b
	inc	hl
	inc	hl
	ld	a,(hl)
	ld	%1,a
	dec	hl
	dec	hl
	; peephole z88dk-433d
}

replace restart {
	ld	l,c
	ld	h,b
	inc	hl
	ld	a,(hl)
	ld	%1,a
	ld	l,c
	ld	h,b
} by {
	ld	l,c
	ld	h,b
	inc	hl
	ld	a,(hl)
	ld	%1,a
	dec	hl
	; peephole z88dk-433e
}

replace restart {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	inc	bc
	inc	bc
	xor	a, a
	ld	(bc),a
	ld	c,%1 (%2)
	ld	b,%3 (%4)
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	inc	bc
	inc	bc
	xor	a, a
	ld	(bc),a
	dec	bc
	dec	bc
	; peephole z88dk-433f1
}

replace restart {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	inc	bc
	xor	a, a
	ld	(bc),a
	ld	c,%1 (%2)
	ld	b,%3 (%4)
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	inc	bc
	xor	a, a
	ld	(bc),a
	dec	bc
	; peephole z88dk-433f2
}

replace restart {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	xor	a, a
	ld	(bc),a
	ld	c,%1 (%2)
	ld	b,%3 (%4)
} by {
	ld	c,%1 (%2)
	ld	b,%3 (%4)
	xor	a, a
	ld	(bc),a
	; peephole z88dk-433f3
}

replace restart {
	ld	c,l
	ld	b,h
	ld	e,%1
	ld	d,%2
	ld	l,c
	ld	h,b
} by {
	ld	c,l
	ld	b,h
	ld	e,%1
	ld	d,%2
	; peephole z88dk-434a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	e,%1 (%3)
	ld	d,%2
	ld	l,c
	ld	h,b
} by {
	ld	c,l
	ld	b,h
	ld	e,%1 (%3)
	ld	d,%2
	; peephole z88dk-434b
}

replace restart {
	ld	c,l
	ld	b,h
	ld	e,%1
	ld	d,%2 (%4)
	ld	l,c
	ld	h,b
} by {
	ld	c,l
	ld	b,h
	ld	e,%1
	ld	d,%2 (%4)
	; peephole z88dk-434c
}

replace restart {
	ld	c,l
	ld	b,h
	ld	e,%1 (%3)
	ld	d,%2 (%4)
	ld	l,c
	ld	h,b
} by {
	ld	c,l
	ld	b,h
	ld	e,%1 (%3)
	ld	d,%2 (%4)
	; peephole z88dk-434d
}

replace restart {
	ld	%1 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	%3,a
	inc	hl
	ld	a,(hl)
	; peephole z88dk-434e1
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	%1 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	c,a
	inc	hl
	ld	a,(hl)
	ld	%3,c
	; peephole z88dk-434e2
} if notUsed('c')

replace restart {
	ld	%1 (%2),a
	inc	hl
	ld	a,(hl)
	ld	%3,%1 (%2)
} by {
	ld	%1 (%2),a
	ld	e,a
	inc	hl
	ld	a,(hl)
	ld	%3,e
	; peephole z88dk-434e3
} if notUsed('e')

replace restart {
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
	dec	hl
	ld	%1,(hl)
} by {
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
	dec	hl
	; peephole z88dk-434f1
} if operandsNotRelated(%1 'hl')
// notVolatile

replace restart {
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
	ld	%3,%4
	dec	hl
	ld	%1,(hl)
} by {
	ld	(hl),%1
	inc	hl
	ld	(hl),%2
	ld	%3,%4
	dec	hl
	; peephole z88dk-434f2
} if operandsNotRelated(%1 %3), operandsNotRelated(%3 'hl'), operandsNotRelated(%1 'hl')
// notVolatile

replace restart {
	ld	(hl),%1
	ld	%2,(hl)
} by {
	ld	(hl),%1
	ld	%2,%1
	; peephole z88dk-434g1
} if notSame(%1 %2)
// notVolatile

replace restart {
	ld	(hl),%1
	ld	%2,(hl)
} by {
	ld	(hl),%1
	; peephole z88dk-434g2
}
// notVolatile

replace restart {
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	dec	hl
	set	%1,b
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	c,(hl)
	inc	hl
	set	%1,(hl)
	ld	b,(hl)
	; peephole z88dk-434h1
}
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	set	%5,b
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	c,(hl)
	inc	hl
	set	%5,(hl)
	ld	b,(hl)
	; peephole z88dk-434h2
}
// notVolatile

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	c,(hl)
	inc	hl
	ld	a,(hl)
	and	a,%5
	ld	b,a
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	(hl),c
	inc	hl
	ld	(hl),b
} by {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ld	c,(hl)
	inc	hl
	ld	a,(hl)
	and	a,%5
	ld	(hl),a
	ld	b,a
	; peephole z88dk-434h3
}
// notVolatile

replace restart {
	ld	%2 (%3),a
	ld	a,%4 (%5)
	adc	a,%1
	ld	%6,%2 (%3)
} by {
	ld	%2 (%3),a
	ld	%6,a
	ld	a,%4 (%5)
	adc	a,%1
	; peephole z88dk-434i1
} if notSame(%1 %6), notSame(%6 'a')
// notVolatile

replace restart {
	ld	%2 (%3),a
	ld	a,%4 (%5)
	add	a,%1
	ld	%6,%2 (%3)
} by {
	ld	%2 (%3),a
	ld	%6,a
	ld	a,%4 (%5)
	add	a,%1
	; peephole z88dk-434i2
} if notSame(%1 %6), notSame(%6 'a')
// notVolatile

replace restart {
	ld	%2 (%3),a
	ld	a,%4 (%5)
	sub	a,%1
	ld	%6,%2 (%3)
} by {
	ld	%2 (%3),a
	ld	%6,a
	ld	a,%4 (%5)
	sub	a,%1
	; peephole z88dk-434i3
} if notSame(%1 %6), notSame(%6 'a')
// notVolatile

replace restart {
	ld	%2 (%3),a
	ld	a,%4 (%5)
	sbc	a,%1
	ld	%6,%2 (%3)
} by {
	ld	%2 (%3),a
	ld	%6,a
	ld	a,%4 (%5)
	sbc	a,%1
	; peephole z88dk-434i4
} if notSame(%1 %6), notSame(%6 'a')
// notVolatile

replace restart {
	ld	a,#<(%1)
	ld	hl,%3
	add	a, (hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%2
	ld	b,a
	ld	a,(bc)
	inc	a
	ld	(bc),a
	ld	a,#<(%1)
	add	a, (hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%2
	ld	b,a
} by {
	ld	a,#<(%1)
	ld	hl,%3
	add	a, (hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%2
	ld	b,a
	ld	a,(bc)
	inc	a
	ld	(bc),a
	; peephole z88dk-434j1
}
// notVolatile

replace restart {
	ld	c,e
	ld	b,d
	ex	de,hl
	call	%1
	push	bc
} by {
	ex	de,hl
	call	%1
	push	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-435a
} if notUsedFrom(%1 'hl')

replace restart {
	ld	hl,#%1
	call	%2
	ld	hl,#%1
} by {
	ld	hl,#%1
	call	%2
	; peephole z88dk-435b
} if notUsedFrom(%2 'hl')

replace restart {
	ld	a,(hl)
	set	%1,a
	ld	%2,a
} by {
	ld	%2,(hl)
	set	%1,%2
	; peephole z88dk-436a
} if notUsed('a'), canAssign(%2 '(hl)')

replace restart {
	ld	a,(hl)
	res	%1,a
	ld	%2,a
} by {
	ld	%2,(hl)
	res	%1,%2
	; peephole z88dk-436b
} if notUsed('a'), canAssign(%2 '(hl)')

replace restart {
	ld	%1,%2
	dec	%1
	ld	%2,%1
} by {
	dec	%2
	ld	%1,%2
	; peephole z88dk-437a
} if canAssign(%2 '(hl)')

replace restart {
	ld	%1,%2
	inc	%1
	ld	%2,%1
} by {
	inc	%2
	ld	%1,%2
	; peephole z88dk-437b
} if canAssign(%2 '(hl)')

replace restart {
	ld	%1,(hl)
	inc	%1
	ld	h,%2
	ld	l,%1
} by {
	ld	l,(hl)
	inc	l
	ld	%1,l
	ld	h,%2
	; peephole z88dk-437c
} if operandsNotRelated(%1 'hl'), notSame(%2 'l')

replace restart {
	ld	%1,(hl)
	dec	%1
	ld	h,%2
	ld	l,%1
} by {
	ld	l,(hl)
	dec	l
	ld	%1,l
	ld	h,%2
	; peephole z88dk-437d
} if operandsNotRelated(%1 'hl'), notSame(%2 'l')

replace restart {
	ld	%1,%2
	dec	%1
	ld	%3,%1
} by {
	ld	%3,%2
	dec	%3
	; peephole z88dk-437e
} if notUsed(%1), canAssign(%1 '(hl)'), canAssign(%2 '(hl)'), canAssign(%3 '(hl)')

replace restart {
	ld	%1,%2
	inc	%1
	ld	%3,%1
} by {
	ld	%3,%2
	inc	%3
	; peephole z88dk-437f
} if notUsed(%1), canAssign(%1 '(hl)'), canAssign(%2 '(hl)'), canAssign(%3 '(hl)')

replace restart {
	ld	a,%1
	srl	a
	ld	%2,a
} by {
	ld	%2,%1
	srl	%2
	; peephole z88dk-437g
} if notUsed('a'), canAssign(%2 '(hl)'), canAssign(%1 '(hl)')

replace restart {
	ld	hl,#%1 + 2
	adc	a, (hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%1 + 3
} by {
	ld	hl,#%1 + 2
	adc	a, (hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	; peephole z88dk-438a
}

replace restart {
	ld	hl,#%1 + 1
	adc	a, (hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%1 + 2
} by {
	ld	hl,#%1 + 1
	adc	a, (hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	; peephole z88dk-438b
}

replace restart {
	ld	hl,#%1
	add	a, (hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%1 + 1
} by {
	ld	hl,#%1
	add	a, (hl)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	; peephole z88dk-438c
}

replace restart {
	inc	hl
	ld	%1,(hl)
	dec	hl
	ld	l,(hl)
	ld	h,%1
} by {
	ld	%1,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,%1
	ld	%1,h
	; peephole z88dk-439
}

replace restart {
	ld	%1 (%2),a
	sub	a,%3
	ld	a,%4
	rla
	ld	%1 (%2),a
} by {
	sub	a,%3
	ld	a,%4
	rla
	ld	%1 (%2),a
	; peephole z88dk-440a
}
// notVolatile

replace restart {
	ld	(%1),de
	ld	hl,%1
	ld	e,(hl)
} by {
	ld	(%1),de
	ld	hl,%1
	; peephole z88dk-440b1
}
// if notVolatile

replace restart {
	ld	(%1 + %2),de
	ld	hl,%1 + %2
	ld	e,(hl)
} by {
	ld	(%1 + %2),de
	ld	hl,%1 + %2
	; peephole z88dk-440b2
}
// if notVolatile

replace restart {
	ld	(%1),bc
	ld	hl,%1
	ld	c,(hl)
} by {
	ld	(%1),bc
	ld	hl,%1
	; peephole z88dk-440b3
}
// if notVolatile

replace restart {
	ld	(%1 + %2),bc
	ld	hl,%1 + %2
	ld	c,(hl)
} by {
	ld	(%1 + %2),bc
	ld	hl,%1 + %2
	; peephole z88dk-440b4
}
// if notVolatile

replace restart {
	xor	a,a
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x0000
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-441a
} if notUsed('a')

replace restart {
	xor	a,a
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	xor	a,a
	ld	l,a
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-441b
}

replace restart {
	xor	a,a
	ld	hl,#%1 + %2
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	ld	hl,#0x0000
	ld	(#%1 + %2),hl
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-441c
} if notUsed('a')

replace restart {
	xor	a,a
	ld	hl,#%1 + %2
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	xor	a,a
	ld	l,a
	ld	h,a
	ld	(#%1 + %2),hl
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-441d
}

replace restart {
	ld	hl,#%1
	ld	(hl),#0x%2
	inc	hl
	ld	(hl),#0x%3
} by {
	ld	hl,#0x%3%2
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-441e
}

replace restart {
	ld	hl,#%1 + %4
	ld	(hl),#0x%2
	inc	hl
	ld	(hl),#0x%3
} by {
	ld	hl,#0x%3%2
	ld	(#%1 + %4),hl
	ld	hl,#%1 + %4 + 1
	; peephole z88dk-441f
}

replace restart {
	ld	hl,(%1)
	ld	bc,#0x0004
	add	hl,bc
	ld	(hl),%2
	inc	hl
	ld	(hl),%3
	ld	bc,(%1)
	ld	hl,#0x0006
	add	hl,bc
} by {
	ld	bc,(%1)
	ld	hl,#0x0004
	add	hl,bc
	ld	(hl),%2
	inc	hl
	ld	(hl),%3
	inc	hl
	; peephole z88dk-442a
} if operandsNotRelated(%2 'bc'), operandsNotRelated(%3 'bc')

replace restart {
	ld	hl,(%1)
	inc	hl
	inc	hl
	inc	hl
	ld	(hl),%2
	ld	bc,(%1)
	ld	hl,#0x0004
	add	hl,bc
} by {
	ld	hl,(%1)
	ld	c,l
	ld	b,h
	inc	hl
	inc	hl
	inc	hl
	ld	(hl),%2
	inc	hl
	; peephole z88dk-442b  INCORRECT IF FLAGS USED
} if operandsNotRelated(%2 'bc')

replace restart {
	ld	bc,(%1)
	inc	bc
	inc	bc
	xor	a,a
	ld	(bc),a
	ld	hl,(%1)
} by {
	ld	hl,(%1)
	inc	hl
	inc	hl
	xor	a,a
	ld	(hl),a
	ld	c,l
	ld	b,h
	dec	hl
	dec	hl
	; peephole z88dk-442c
}
// notVolatile

replace restart {
	ld	hl,#%1
	ldi
	ld	a,(hl)
	ld	(de),a
	ld	hl,(#%1)
} by {
	ld	hl,(#%1)
	ex	de,hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ex	de,hl
	ld	a,h
	dec	bc
	; peephole z88dk-442d1
}

replace restart {
	ld	(%1),hl
	ex	de,hl
	ld	hl,#%2
	ldi
	ld	a,(hl)
	ld	(de),a
	ld	hl,(%1)
} by {
	ld	(%1),hl
	ld	de,(#%2)
	ld	(hl),e
	inc	hl
	ld	(hl),d
	ld	a,d
	ld	e,l
	ld	d,h
	dec	bc
	dec	hl
	; peephole z88dk-442d2
}
// notVolatile

replace restart {
	inc	de
	inc	de
	inc	de
	inc	de
	inc	de
} by {
	ld	hl,#0x0005
	add	hl,de
	ex	de,hl
	; peephole z88dk-443a  INCORRECT IF FLAGS USED
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	add	hl,de
	ex	de,hl
	inc	de
} by {
	ld	hl,#%1+1
	add	hl,de
	ex	de,hl
	; peephole z88dk-443b  INCORRECT IF FLAGS USED
} if notUsed('hl')

replace restart {
	inc	bc
	inc	bc
	inc	bc
	inc	bc
	inc	bc
} by {
	ld	hl,#0x0005
	add	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-443c  INCORRECT IF FLAGS USED
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	add	hl,bc
	ld	c,l
	ld	b,h
	inc	bc
} by {
	ld	hl,#%1+1
	add	hl,bc
	ld	c,l
	ld	b,h
	; peephole z88dk-443d  INCORRECT IF FLAGS USED
} if notUsed('hl')

replace restart {
	ld	(hl),#%1
	ld	%2,#%1
} by {
	ld	%2,#%1
	ld	(hl),%2
	; peephole z88dk-444
} if canAssign(%2 '(hl)'), operandsNotRelated(%2 'hl')

replace restart {
	push	%1
	ld	sp,%2
} by {
	ld	sp,%2
	; peephole z88dk-445a
}

replace restart {
	pop	%1
	ld	sp,%2
} by {
	ld	sp,%2
	; peephole z88dk-445b
} if notSame(%1 %2), notUsed(%1)

replace restart {
	ld	hl,#%1
	ld	(hl),%2
	inc	hl
	ld	(hl),%3
} by {
	ld	l,%2
	ld	h,%3
	ld	(#%1),hl
	; peephole z88dk-446
} if notUsed('hl'), operandsNotRelated(%2 'hl'), operandsNotRelated(%3 'hl')

replace restart {
	ld	c,%1 (%2)
	ld	b,%3
	ld	l,c
	ld	h,b
} by {
	ld	l,%1 (%2)
	ld	h,%3
	ld	c,l
	ld	b,h
	; peephole z88dk-447
} if notSame(%3 'l')

replace restart {
	ld	a,(%2)
	res	%1,a
	ld	(%2),a
} by {
	ld	hl,%2
	res	%1,(hl)
	ld	a,(hl)
	; peephole z88dk-448a
} if notUsed('hl'), operandsNotRelated(%2 'bc'), operandsNotRelated(%2 'de'), operandsNotRelated(%2 'hl')

replace restart {
	ld	a,(%2)
	set	%1,a
	ld	(%2),a
} by {
	ld	hl,%2
	set	%1,(hl)
	ld	a,(hl)
	; peephole z88dk-448b
} if notUsed('hl'), operandsNotRelated(%2 'bc'), operandsNotRelated(%2 'de'), operandsNotRelated(%2 'hl')

replace restart {
	ld	a,(%2)
	bit	%1,a
	ld	(%2),a
} by {
	ld	hl,%2
	bit	%1,(hl)
	ld	a,(hl)
	; peephole z88dk-448c
} if notUsed('hl'), operandsNotRelated(%2 'bc'), operandsNotRelated(%2 'de'), operandsNotRelated(%2 'hl')

replace restart {
	ld	a,(%2 + %3)
	res	%1,a
	ld	(%2 + %3),a
} by {
	ld	hl,%2 + %3
	res	%1,(hl)
	ld	a,(hl)
	; peephole z88dk-448d
} if notUsed('hl')

replace restart {
	ld	a,(%2 + %3)
	set	%1,a
	ld	(%2 + %3),a
} by {
	ld	hl,%2 + %3
	set	%1,(hl)
	ld	a,(hl)
	; peephole z88dk-448e
} if notUsed('hl')

replace restart {
	ld	a,(%2 + %3)
	bit	%1,a
	ld	(%2 + %3),a
} by {
	ld	hl,%2 + %3
	bit	%1,(hl)
	ld	a,(hl)
	; peephole z88dk-448f
} if notUsed('hl')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	inc	hl
	inc	hl
	; peephole z88dk-449a
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,b
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	res	%1,(hl)
	inc	hl
	inc	hl
	; peephole z88dk-449b
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,e
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	inc	hl
	res	%1,(hl)
	inc	hl
	; peephole z88dk-449c
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	inc	hl
	inc	hl
	res	%1,(hl)
	; peephole z88dk-449d
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,b
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	inc	hl
	inc	hl
	; peephole z88dk-449e
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,e
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	inc	hl
	res	%2,(hl)
	inc	hl
	; peephole z88dk-449f
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	inc	hl
	inc	hl
	res	%2,(hl)
	; peephole z88dk-449g
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,b
	res	%2,e
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	inc	hl
	; peephole z88dk-449h
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,b
	res	%2,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	res	%1,(hl)
	inc	hl
	inc	hl
	res	%2,(hl)
	; peephole z88dk-449i
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,e
	res	%2,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	inc	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	; peephole z88dk-449j
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,b
	res	%3,e
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	inc	hl
	res	%3,(hl)
	inc	hl
	; peephole z88dk-449k
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,e
	res	%3,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	inc	hl
	res	%2,(hl)
	inc	hl
	res	%3,(hl)
	; peephole z88dk-449l
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,b
	res	%3,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	inc	hl
	inc	hl
	res	%3,(hl)
	; peephole z88dk-449l
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,b
	res	%2,e
	res	%3,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	inc	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	inc	hl
	res	%3,(hl)
	; peephole z88dk-449m
} if notUsed('bc'), notUsed('de')

replace restart {
	push	hl
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	res	%1,c
	res	%2,b
	res	%3,e
	res	%4,d
	pop	hl
	push	hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
} by {
	push	hl
	res	%1,(hl)
	inc	hl
	res	%2,(hl)
	inc	hl
	res	%3,(hl)
	inc	hl
	res	%4,(hl)
	; peephole z88dk-449n
} if notUsed('bc'), notUsed('de')

replace restart {
	add	a,#0x00
} by {
	or	a,a
	; peephole z88dk-450a
}

replace restart {
	sub	a,#0x00
} by {
	or	a,a
	; peephole z88dk-450b
}

replace restart {
	pop	bc
	ld	l,c
	ld	h,b
} by {
	pop	hl
	; peephole z88dk-451a
} if notUsed('bc')

replace restart {
	pop	bc
	ld	%1,%2
	ld	l,c
	ld	h,b
} by {
	pop	hl
	ld	%1,%2
	; peephole z88dk-451b
} if notUsed('bc'), operandsNotRelated(%1 'bc'), operandsNotRelated(%1 'hl'), operandsNotRelated(%2 'bc')

replace restart {
	pop	bc
	ld	%1,%2 + %3
	ld	l,c
	ld	h,b
} by {
	pop	hl
	ld	%1,%2 + %3
	; peephole z88dk-451c
} if notUsed('bc'), operandsNotRelated(%1 'bc'), operandsNotRelated(%1 'hl')
	
replace restart {
	ld	c,l
	ld	b,h
	ld	(hl),%1
	inc	bc
	ld	(bc),a
} by {
	ld	(hl),%1
	inc	hl
	ld	(hl),a
	dec	hl
	; peephole z88dk-452
} if notUsed('bc'), operandsNotRelated(%1 'bc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	ld	a,(hl)
	ld	(bc),a
	inc	bc
	inc	hl
	ld	a,(hl)
	ld	(bc),a
} by {
	ld	bc,(#%1)
	ld	(hl),c
	inc	hl
	ld	(hl),b
	ld	a,b
	ld	hl,#%1 + 1
	; peephole z88dk-453
} if notUsed('bc')

replace restart {
	%1	bc
	sla	c
	rl	b
} by {
	ld	l,c
	ld	h,b
	%1	hl
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-454a
} if notUsed('hl')

replace restart {
	%1	de
	sla	e
	rl	d
} by {
	ld	l,e
	ld	h,d
	%1	hl
	add	hl,hl
	ld	e,l
	ld	d,h
	; peephole z88dk-454b
} if notUsed('hl')	

replace restart {
	ld	(#%1),hl
	inc	%2
	ld	hl,(#%1)
} by {
	ld	(#%1),hl
	inc	%2
	; peephole z88dk-455
} if operandsNotRelated(%2 'hl'), notVolatile(%1)

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	and	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	and	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	a,(#%2)
	and	a,l
	ld	l,a
	ld	a,(#%2 + 1)
	and	a,h
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-456a
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	or	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	or	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	a,(#%2)
	or	a,l
	ld	l,a
	ld	a,(#%2 + 1)
	or	a,h
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-456b
}

replace restart {
	ld	a,(#%1)
	ld	hl,#%2
	xor	a, (hl)
	ld	hl,#%1
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,#%2 + 1
	xor	a, (hl)
	ld	(#%1 + 1),a
} by {
	ld	hl,(#%1)
	ld	a,(#%2)
	xor	a,l
	ld	l,a
	ld	a,(#%2 + 1)
	xor	a,h
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%2 + 1
	; peephole z88dk-456c
}

replace restart {
	ld	a,%1
	xor	a,%1
} by {
	xor	a,a
	; peephole z88dk-456d
} 
//if notVolatile(%1)
	
replace restart {
	ld	hl,#%1
	ld	a,(hl)
	cpl
	ld	c,a
	inc	hl
	ld	a,(hl)
	cpl
	ld	b,a
	ld	a,(#%2)
	xor	a, c
	ld	(#%1),a
	ld	a,(#%2 + 1)
	xor	a, b
	ld	(#%1 + 1),a
} by {
	ld	bc,(#%1)
	ld	hl,(#%2)
	ld	a,c
	cpl
	xor	a,l
	ld	l,a
	ld	a,b
	cpl
	xor	a,h
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-457d1
} if notUsed('bc')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	cpl
	ld	c,a
	inc	hl
	ld	a,(hl)
	cpl
	ld	b,a
	ld	a,(#%2)
	xor	a, c
	ld	(#%1),a
	ld	a,(#%2 + 1)
	xor	a, b
	ld	(#%1 + 1),a
} by {
	ld	bc,(#%1)
	ld	hl,(#%2)
	ld	a,c
	cpl
	ld	c,a
	xor	a,l
	ld	l,a
	ld	a,b
	cpl
	ld	b,a
	xor	a,h
	ld	h,a
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-457d2
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1)
	add	hl,bc
	ld	de,#%2
	ldi
} by {
	ld	bc,(#%1)
	add	hl,bc
	ld	de,#%2
	ldi
	; peephole z88dk-458
} if notUsed('bc')

replace restart {
	ld	l, c
	ld	h, b
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	push	bc
} by {
	ld	l,c
	ld	h,b
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	dec	hl
	push	hl
	; peephole z88dk-459a
} if notUsed('bc'), notUsed('hl')

replace restart {
	%1	bc
	ld	l,c
	ld	h,b
} by {
	ld	l,c
	ld	h,b
	%1	hl
	; peephole z88dk-459b
} if notUsed('bc')

replace restart {
	ld	a,#0x00
	ld	(hl),a
	inc	hl
	ld	(hl),a
} by {
	xor	a,a
	ld	(hl),a
	inc	hl
	ld	(hl),a
	; peephole z88dk-459c
}

replace restart {
	ld	bc,(#%1)
	ld	hl,(#%2)
	push	hl
	push	bc
} by {
	ld	hl,(#%2)
	push	hl
	ld	hl,(#%1)
	push	hl
	; peephole z88dk-459d
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	b,h
	%1	e
} by {
	%1	e
	ld	b,h
	; peephole z88dk-459e1
}

replace restart {
	ld	b,h
	%1	d
} by {
	%1	d
	ld	b,h
	; peephole z88dk-459e2
}

replace restart {
	ld	c,l
	%1	e
} by {
	%1	e
	ld	c,l
	; peephole z88dk-459e3
}

replace restart {
	ld	c,l
	%1	d
} by {
	%1	d
	ld	c,l
	; peephole z88dk-459e4
}

replace restart {
	ld	b,h
	%1	a,c
} by {
	%1	a,c
	ld	b,h
	; peephole z88dk-459e5
}

replace restart {
	ld	b,h
	%1	a,b
} by {
	%1	a,h
	ld	b,h
	; peephole z88dk-459e6
}

replace	restart {
	ld	c,l
	%1	a,c
} by {
	%1	a,l
	ld	c,l
	; peephole z88dk-459e7
}

replace restart {
	ld	c,l
	%1	a,b
} by {
	%1	a,b
	ld	c,l
	; peephole z88dk-459e8
}
	
replace restart {
	ld	b,h
	ld	a,%1
} by {
	ld	a,%1
	ld	b,h
	; peephole z88dk-459e9
} if operandsNotRelated(%1 'b')

replace restart {
	ld	c,l
	ld	a,%1
} by {
	ld	a,%1
	ld	c,l
	; peephole z88dk-459e10
} if operandsNotRelated(%1 'c')

replace restart {
	ld	b,h
	%1	a,%2
} by {
	%1	a,%2
	ld	b,h
	; peephole z88dk-459e11
} if operandsNotRelated(%2 'b')

replace restart {
	ld	c,l
	%1	a,%2
} by {
	%1	a,%2
	ld	c,l
	; peephole z88dk-459e12
} if operandsNotRelated(%2 'c')

replace restart {
	ld	b,h
	rla
} by {
	rla
	ld	b,h
	; peephole z88dk-459e13
}

replace restart {
	ld	c,l
	rla
} by {
	rla
	ld	c,l
	; peephole z88dk-459e14
}

replace restart {
	ld	b,h
	ld	%1 (%2),%3
} by {
	ld	%1 (%2),%3
	ld	b,h
	; peephole z88dk-459e15
} if notSame(%3 'b')

replace restart {
	ld	c,l
	ld	%1 (%2),%3
} by {
	ld	%1 (%2),%3
	ld	c,l
	; peephole z88dk-459e16
} if notSame(%3 'c')

replace restart {
	ld	b,h
	ld	%3,%1 (%2)
} by {
	ld	%3,%1 (%2)
	ld	b,h
	; peephole z88dk-459e17a
} if notSame(%3 'b'), notSame(%3 'h')

replace restart {
	ld	c,l
	ld	%3,%1 (%2)
} by {
	ld	%3,%1 (%2)
	ld	c,l
	; peephole z88dk-459e18a
} if notSame(%3 'c'), notSame(%3 'l')

replace restart {
	ld	b,h
	add	%3,%1 (%2)
} by {
	add	%3,%1 (%2)
	ld	b,h
	; peephole z88dk-459e17b
} if notSame(%3 'b'), notSame(%3 'h')

replace restart {
	ld	c,l
	add	%3,%1 (%2)
} by {
	add	%3,%1 (%2)
	ld	c,l
	; peephole z88dk-459e18b
} if notSame(%3 'c'), notSame(%3 'l')

replace restart {
	ld	b,h
	sub	%3,%1 (%2)
} by {
	sub	%3,%1 (%2)
	ld	b,h
	; peephole z88dk-459e17c
} if notSame(%3 'b'), notSame(%3 'h')

replace restart {
	ld	c,l
	sub	%3,%1 (%2)
} by {
	sub	%3,%1 (%2)
	ld	c,l
	; peephole z88dk-459e18d
} if notSame(%3 'c'), notSame(%3 'l')

replace restart {
	ld	b,h
	adc	%3,%1 (%2)
} by {
	adc	%3,%1 (%2)
	ld	b,h
	; peephole z88dk-459e17e
} if notSame(%3 'b'), notSame(%3 'h')

replace restart {
	ld	c,l
	adc	%3,%1 (%2)
} by {
	adc	%3,%1 (%2)
	ld	c,l
	; peephole z88dk-459e18f
} if notSame(%3 'c'), notSame(%3 'l')

replace restart {
	ld	b,h
	sbc	%3,%1 (%2)
} by {
	sbc	%3,%1 (%2)
	ld	b,h
	; peephole z88dk-459e17g
} if notSame(%3 'b'), notSame(%3 'h')

replace restart {
	ld	c,l
	sbc	%3,%1 (%2)
} by {
	sbc	%3,%1 (%2)
	ld	c,l
	; peephole z88dk-459e18h
} if notSame(%3 'c'), notSame(%3 'l')

replace restart {
	ld	b,h
	ld	c,l
} by {
	ld	c,l
	ld	b,h
	; peephole z88dk-459e19
}

replace restart {
	ld	%1 (%2),#%9
	ld	%3 (%4),#%9
	ld	%5 (%6),#%9
	ld	%7 (%8),#%9
} by {
	ld	a,#%9
	ld	%1 (%2),a
	ld	%3 (%4),a
	ld	%5 (%6),a
	ld	%7 (%8),a
	; peephole z88dk-460a
} if notUsed('a')

replace restart {
	ld	%1 (%2),#%9
	ld	%3 (%4),#%9
	ld	%5 (%6),#%9
} by {
	ld	a,#%9
	ld	%1 (%2),a
	ld	%3 (%4),a
	ld	%5 (%6),a
	; peephole z88dk-460b
} if notUsed('a')

//replace restart {
//	ld	%1 (%2),#%9
//	ld	%3 (%4),#%9
//} by {
//	ld	a,#%9
//	ld	%1 (%2),a
//	ld	%3 (%4),a
//	; peephole z88dk-460c
//} if notUsed('a')

replace restart {
	ld	l,e
	ld	h,d
	%1	de
	ld	a,h
	or	a,l
} by {
	ld	a,d
	or	a,e
	ld	l,e
	ld	h,d
	%1	de
	; peephole z88dk-461a
}

replace restart {
	ld	l,c
	ld	h,b
	%1	bc
	ld	a,h
	or	a,l
} by {
	ld	a,b
	or	a,c
	ld	l,c
	ld	h,b
	%1	bc
	; peephole z88dk-461b
}

replace restart {
	ld	(#%1),bc
	ld	de,(#%1)
} by {
	ld	(#%1),bc
	ld	e,c
	ld	d,b
	; peephole z88dk-462a
}
// if notVolatile

replace restart {
	ld	(#%1),bc
	ld	hl,(#%1)
} by {
	ld	l,c
	ld	h,b
	ld	(#%1),hl
	; peephole z88dk-462b
}
// if notVolatile

replace restart {
	ld	(#%1),de
	ld	bc,(#%1)
} by {
	ld	(#%1),de
	ld	c,e
	ld	b,d
	; peephole z88dk-462c
}
// if notVolatile

replace restart {
	ld	(#%1),de
	ld	hl,(#%1)
} by {
	ld	l,e
	ld	h,d
	ld	(#%1),hl
	; peephole z88dk-462d
}
// if notVolatile

replace restart {
	ld	(#%1),%2
	ld	%2,(#%1)
} by {
	ld	(#%1),%2
	; peephole z88dk-462e
}
// if notVolatile

replace restart {
	ld	%1,#%2
	inc	%1
} by {
	ld	%1,#%2+1
	; peephole z88dk-463a
} if notSame(%1 '(hl)')

replace restart {
	ld	%1,#%2 + %3
	inc	%1
} by {
	ld	%1,#%2 + %3+1
	; peephole z88dk-463b
} if same(%1 'bc' 'de' 'hl')

replace restart {
	ld	%1,#%2
	dec	%1
} by {
	ld	%1,#%2-1
	; peephole z88dk-463c
} if notSame(%1 '(hl)')

replace restart {
	ld	%1,#%2 + %3
	dec	%1
} by {
	ld	%1,#%2 + %3-1
	; peephole z88dk-463d
} if notSame(%1 '(hl)')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	push	af
	inc	sp
	dec	hl
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	hl,(#%1 + %2-1)
	push	hl
	ld	a,h
	ld	hl,#%1 + %2-1
	; peephole z88dk-464a
}

replace restart {
	ld	hl,#%1 + %2
	ld	(hl),a
	push	af
	inc	sp
	dec	hl
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	(#%1 + %2),a
	ld	hl,(#%1 + %2-1)
	push	hl
	ld	a,h
	ld	hl,#%1 + %2-1
	; peephole z88dk-464b
}

replace restart {
	ld	hl,(#%1)
	ld	%2,%3
	ld	bc,(#%1)
} by {
	ld	hl,(#%1)
	ld	%2,%3
	ld	c,l
	ld	b,h
	; peephole z88dk-465a
} if operandsNotRelated('hl' %2)

replace restart {
	ld	hl,(#%1 + %4)
	ld	%2,%3
	ld	bc,(#%1 + %4)
} by {
	ld	hl,(#%1 + %4)
	ld	%2,%3
	ld	c,l
	ld	b,h
	; peephole z88dk-465b
} if operandsNotRelated('hl' %2)

replace restart {
	ld	bc,(%1)
	ld 	l,c
	ld	h,b
} by {
	ld	hl,(%1)
	ld	c,l
	ld	b,h
	; peephole z88dk-466a
}

replace restart {
	ld	de,(%1)
	ld	l,e
	ld	h,d
} by {
	ld	hl,(%1)
	ld	e,l
	ld	d,h
	; peephole z88dk-466b
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,c
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,b
	ld	(hl),a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	(#%1),hl
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-467a
}

replace restart {
	pop	bc
	ld	a,c
	sub	a, e
	ld	c,a
	ld	a,b
	sbc	a, d
	ld	b,a
} by {
	pop	hl
	xor	a,a
	sbc	hl,de
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-467b
} if notUsed('hl')

replace restart {
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	inc	hl
} by {
	push	af
	ld	bc,#7
	add	hl,bc
	pop	af
	; peephole z88dk-468a1
} if notUsed('bc')

replace restart {
	push	af
	ld	bc,#%1
	add	hl,bc
	pop	af
	inc	hl
} by {
	push	af
	ld	bc,#%1+1
	add	hl,bc
	pop	af
	; peephole z88dk-468a2
}

replace restart {
	inc	hl
	push	af
	ld	bc,#%1
	add	hl,bc
	pop	af
} by {
	push	af
	ld	bc,#%1+1
	add	hl,bc
	pop	af
	; peephole z88dk-468a3
}

replace restart {
	push	af
	ld	bc,#%1
	add	hl,bc
	pop	af
	push	af
	ld	bc,#%2
	add	hl,bc
	pop	af
} by {
	push	af
	ld	bc,#%1+%2
	add	hl,bc
	pop	af
	; peephole z88dk-468a4
}

replace restart {
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	inc	hl
	inc	hl
} by {
	push	af
	ld	de,#7
	add	hl,de
	pop	af
	; peephole z88dk-468b1
} if notUsed('de')

replace restart {
	push	af
	ld	de,#%1
	add	hl,de
	pop	af
	inc	hl
} by {
	push	af
	ld	de,#%1+1
	add	hl,de
	pop	af
	; peephole z88dk-468b2
}

replace restart {
	inc	hl
	push	af
	ld	de,#%1
	add	hl,de
	pop	af
} by {
	push	af
	ld	de,#%1+1
	add	hl,de
	pop	af
	; peephole z88dk-468b3
}

replace restart {
	push	af
	ld	de,#%1
	add	hl,de
	pop	af
	push	af
	ld	de,#%2
	add	hl,de
	pop	af
} by {
	push	af
	ld	de,#%1+%2
	add	hl,de
	pop	af
	; peephole z88dk-468b4
}

replace restart {
	ld	a,(hl)
	ld	(de),a
	ex	de,hl
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ldi
	ld	a,(hl)
	ld	(de),a
	ex	de,hl
	; peephole z88dk-469a
} if notUsed('bc')

replace restart {
	ld	a,(hl)
	ld	(de),a
	ex	de,hl
	inc	de
	ld	a,(de)
	inc	hl
	ld	(hl),a
} by {
	ldi
	inc	bc
	ld	a,(hl)
	ld	(de),a
	ex	de,hl
	; peephole z88dk-469b
}

replace restart {
	ld	a,(hl)
	ld	(bc),a
	inc	bc
	inc	hl
	ld	a,(hl)
	ld	(bc),a
	inc	bc
	inc	hl
} by {
	ld	e,c
	ld	d,b
	ld	a,(hl)
	ldi
	ldi
	ld	c,e
	ld	b,d
	; peephole z88dk-470a
} if notUsed('de')

replace restart {
	ld	c,e
	ld	b,d
	ld	a,(hl)
	ld	(bc),a
	inc	bc
	inc	hl
} by {
	ldi
	ld	c,e
	ld	b,d
	; peephole z88dk-470b
} if notUsed('de')

replace restart {
	ld	c,e
	ld	b,d
	ld	e,c
	ld	d,b
} by {
	ld	c,e
	ld	b,d
	; peephole z88dk-470c
}

replace restart {
	ld	c,e
	ld	b,d
	ld	a,(hl)
	ld	(bc),a
} by {
	ld	a,(hl)
	ld	(de),a
	ld	c,e
	ld	b,d
	; peephole z88dk-470d
}

replace restart {
	ld	%1,%2 (%6)
	ld	%3,%4 (%7)
	ld	%5,%2 (%6)
} by {
	ld	%1,%2 (%6)
	ld	%3,%4 (%7)
	ld	%5,%1
	; peephole z88dk-471a
} if notSame(%1 %3)

replace restart {
	ld	%1,%2 (%6)
	ld	%3,%4
	ld	%5,%2 (%6)
} by {
	ld	%1,%2 (%6)
	ld	%3,%4
	ld	%5,%1
	; peephole z88dk-471b
} if operandsNotRelated(%1 %3)

replace restart {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	c,l
	ld	l,%1 (%2)
	ld	b,h
	ld	h,%3 (%4)
} by {
	ld	%1 (%2),l
	ld	%3 (%4),h
	ld	c,l
	ld	b,h
	; peephole z88dk-471c
}
// if notVolatile

replace restart {
	ld	%3,l
	ld	hl,#%1
	ld	(hl),%3
	inc	hl
	ld	a,#0x%2
	ld	(hl),a
} by {
	ld	h,#0x%2
	ld	%3,l
	ld	a,h
	ld	(#%1),hl
	ld	hl,#%1 + 1
	; peephole z88dk-472a
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	(#%1),hl
	ld	hl,#%1
	or	a,(hl)
} by {
	ld	(#%1),hl
	or	a,l
	ld	hl,#%1
	; peephole z88dk-472b
}

replace restart {
	ld	(#%1),hl
	ld	hl,#%1 + 1
	or	a,(hl)
} by {
	ld	(#%1),hl
	or	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-472c
}

replace restart {
	ld	hl,#(%1 + %2)
	ld	(hl),%10
	ld	hl,#(%1 + %3)
	ld	(hl),%11
	ld	hl,#(%1 + %4)
	ld	(hl),%12
} by {
	ld	hl,#(%1 + %2)
	ld	(hl),%10
	inc	hl
	ld	(hl),%11
	inc	hl
	ld	(hl),%12
	; peephole z88dk-473a
} if inSequence('1' %2 %3 %4)

replace restart {
	ld	hl,#%1
	ld	(hl),%10
	ld	hl,#(%1 + 0x0001)
	ld	(hl),%11
} by {
	ld	hl,#%1
	ld	(hl),%10
	inc	hl
	ld	(hl),%11
	; peephole z88dk-473b
}

replace restart {
	ld	hl,#(%1 + %2)
	ld	(hl),%10
	ld	hl,#(%1 + %3)
	ld	(hl),%11
} by {
	ld	hl,#(%1 + %2)
	ld	(hl),%10
	inc	hl
	ld	(hl),%11
	; peephole z88dk-473c
} if inSequence('1' %2 %3)

replace restart {
	ld	c,l
	ld	b,h
	ld	(%1),bc
} by {
	ld	(%1),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-474a
}

replace restart {
	ld	c,l
	ld	b,h
	ld	(%1 + %2),bc
} by {
	ld	(%1 + %2),hl
	ld	c,l
	ld	b,h
	; peephole z88dk-474b
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	%5	a,#%6
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	bc,#%1
	add	hl,bc
	ld	a,(hl)
	ld	c,l
	ld	b,h
	%5	a,#%6
	ld	hl,#%2
	; peephole z88dk-475a1
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	ld	c,a
	ld	a,#%4
	%5	a,c
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	bc,#%1
	add	hl,bc
	ld	c,(hl)
	ld	b,h
	ld	a,#%4
	%5	a,c
	ld	hl,#%2
	; peephole z88dk-475a2
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	ld	c,a
	or	a,a
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	bc,#%1
	add	hl,bc
	ld	a,(hl)
	ld	c,a
	ld	b,h
	or	a,a
	ld	hl,#%2
	; peephole z88dk-475a3
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	bc,#%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-475b
} if notUsed('hl')

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a,(hl)
	ld	e,a
	ld	a,b
	adc	a,#%2
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	h,#%2
	add	hl,bc
	ld	a,h
	ld	e,l
	ld	d,h
	; peephole z88dk-475c
} if notUsed('hl')

replace restart {
	ld	a,c
	ex	de,hl
	ld	hl,#%1
	add	a, (hl)
	ld	c,a
	ld	a,b
	adc	a,#%2
	ld	b,a
	ld	a,(bc)
} by {
	ex	de,hl
	ld	hl,(#%1)
	ld	h,#%2
	add	hl,bc
	ld	a,(hl)
	ld	c,l
	ld	b,h
	; peephole z88dk-475d1
} if notUsed('hl')

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a, (hl)
	ld	c,a
	ld	a,b
	adc	a,#%2
	ld	b,a
	ld	a,(bc)
} by {
	ld	hl,(#%1)
	ld	h,#%2
	add	hl,bc
	ld	a,(hl)
	ld	c,l
	ld	b,h
	; peephole z88dk-475d2
} if notUsed('hl')

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a,(hl)
	ld	e,a
	ld	a,b
	inc	hl
	adc	a,(hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	a,h
	ld	e,l
	ld	d,h
	; peephole z88dk-475d3a
} if notUsed('hl')

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a,(hl)
	ld	e,a
	ld	a,b
	inc	hl
	adc	a,(hl)
	ld	d,a
} by {
	ld	hl,(#%1)
	add	hl,bc
	ld	e,l
	ld	d,h
	ld	hl,#%1 + 1
	; peephole z88dk-475d3b
} if notUsed('a')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
} by {
	ld	hl,(#%1)
	ld	h,#%3
	ld	bc,#%1
	add	hl,bc
	ld	a,(hl)
	ld	c,l
	ld	b,h
	; peephole z88dk-475e1
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a,(hl)
	ld	e,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	d,a
	ld	a,(de)
} by {
	ld	e,(hl)
	ld	d,#%3
	ld	hl,#%1
	add	hl,de
	ld	a,(hl)
	ex	de,hl
	; peephole z88dk-475e2
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
} by {
	ld	c,(hl)
	ld	b,#%3
	ld	hl,#%1
	add	hl,bc
	ld	a,(hl)
	; peephole z88dk-475e3
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	a,c
	add	a,#0x%1
	ld	l,a
	ld	a,b
	adc	a,#0x%2
	ld	h,a
} by {
	ld	hl,#0x%2%1
	add	hl,bc
	ld	a,h
	; peephole z88dk-475e4
}

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a, (hl)
	ld	e,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	d,a
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	de,#%1
	add	hl,de
	ex	de,hl
	; peephole z88dk-475f1
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	a,#<(%1)
	ld	c,l
	ld	b,h
	ld	hl,#%2
	add	a, (hl)
	ld	e,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	d,a
} by {
	ld	c,l
	ld	b,h
	ld	hl,(#%2)
	ld	h,#%3
	ld	de,#%1
	add	hl,de
	ex	de,hl
	; peephole z88dk-475f2
} if notUsed('hl'), notUsed('a')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	ld	c,a
	ld	b,#%4
	ld	e,(hl)
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	e,l
	ld	bc,#%1
	add	hl,bc
	ld	c,(hl)
	ld	b,#%4
	ld	a,c
	; peephole z88dk-475g1
} if notUsed('hl')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	ld	b,a
	ld	e,(hl)
} by {
	ld	hl,(#%2)
	ld	h,#%3
	ld	e,l
	ld	bc,#%1
	add	hl,bc
	ld	c,l
	ld	b,(hl)
	ld	a,b
	; peephole z88dk-475g2
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	add	a,#<(%2)
	ld	c,a
	ld	a,#>(%2)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	ld	c,a
} by {
	ld	hl,(#%1)
	ld	h,#%3
	ld	bc,#%2
	add	hl,bc
	ld	c,(hl)
	ld	b,h
	ld	a,c
	; peephole z88dk-475h1
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	add	a,#<(%2)
	ld	c,a
	ld	a,#>(%2)
	adc	a,#%3
	ld	b,a
	ld	a,(bc)
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	h,#%3
	ld	bc,#%2
	add	hl,bc
	ld	c,l
	ld	b,(hl)
	ld	a,b
	; peephole z88dk-475h2
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	add	a,#<(%2)
	ld	e,a
	ld	a,#>(%2)
	adc	a,#%3
	ld	d,a
	ld	a,(de)
} by {
	ld	hl,(#%1)
	ld	h,#%3
	ld	de,#%2
	add	hl,de
	ld	a,(hl)
	ex	de,hl
	; peephole z88dk-475i
} if notUsed('hl')

replace restart {
	ld	a,e
	ld	hl,#%1
	add	a,(hl)
	ld	c,a
	ld	a,d
	inc	hl
	adc	a,(hl)
	ld	b,a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-475j
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	%2	a,c
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	h,a
	ld	l,c
} by {
	ld	b,d
	ld	hl,(#%1)
	%2	hl,bc
	ld	a,h
	ld	c,l
	; peephole z88dk-475k1
} if notUsed('b'), same(%2 'add' 'adc')

replace restart {
	ld	hl,#%1 + %3
	ld	a,(hl)
	%2	a,c
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	h,a
	ld	l,c
} by {
	ld	b,d
	ld	hl,(#%1 + %3)
	%2	hl,bc
	ld	a,h
	ld	c,l
	; peephole z88dk-475k1b
} if notUsed('b'), same(%2 'add' 'adc')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	%2	a,c
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	h,a
	ld	l,c
} by {
	ld	a,b
	ld	b,d
	ld	hl,(#%1)
	%2	hl,bc
	ld	b,a
	ld	a,h
	ld	c,l
	; peephole z88dk-475k2a
} if same(%2 'add' 'adc')

replace restart {
	ld	hl,#%1 + %3
	ld	a,(hl)
	%2	a,c
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	h,a
	ld	l,c
} by {
	ld	a,b
	ld	b,d
	ld	hl,(#%1 + %3)
	%2	hl,bc
	ld	b,a
	ld	a,h
	ld	c,l
	; peephole z88dk-475k2b
} if same(%2 'add' 'adc')

replace restart {
	ld	a,l
	ld	b,h
	ld	hl,#%1
	%2	a,(hl)
	ld	e,a
	ld	a,b
	inc	hl
	adc	a,(hl)
	ld	d,a
} by {
	ld	b,h
	ld	de,(#%1)
	%2	hl,de
	ld	a,h
	ld	e,l
	ld	d,h
	ld	hl,#%1 + 1
	; peephole z88dk-475l1
} if same(%2 'add' 'adc')

replace restart {
	ld	a,l
	ld	b,h
	ld	hl,#%1 + %3
	%2	a,(hl)
	ld	e,a
	ld	a,b
	inc	hl
	adc	a,(hl)
	ld	d,a
} by {
	ld	b,h
	ld	de,(#%1 + %3)
	%2	hl,de
	ld	a,h
	ld	e,l
	ld	d,h
	ld	hl,#%1 + %3 + 1
	; peephole z88dk-475l2
} if same(%2 'add' 'adc')

replace restart {
	ld	a,e
	ld	c,l
	ld	b,h
	ld	hl,#%1
	%2	a,(hl)
	ld	e,a
	ld	a,d
	inc	hl
	adc	a,(hl)
	ld	d,a
} by {
	ld	c,l
	ld	b,h
	ld	hl,(#%1)
	%2	hl,de
	ld	a,h
	ld	e,l
	ld	d,h
	ld	hl,#%1 + 1
	; peephole z88dk-475m1
}

replace restart {
	ld	a,e
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %3
	%2	a,(hl)
	ld	e,a
	ld	a,d
	inc	hl
	adc	a,(hl)
	ld	d,a
} by {
	ld	c,l
	ld	b,h
	ld	hl,(#%1 + %3)
	%2	hl,de
	ld	a,h
	ld	e,l
	ld	d,h
	ld	hl,#%1 + %3 + 1
	; peephole z88dk-475m2
}

replace restart {
	ld	(%1),a
	xor	a,%2
	ld	(%1),a
} by {
	xor	a,%2
	ld	(%1),a
	; peephole z88dk-476a
}
// if notVolatile

replace restart {
	ld	(%1),a
	or	a,%2
	ld	(%1),a
} by {
	or	a,%2
	ld	(%1),a
	; peephole z88dk-476b
}
// if notVolatile

replace restart {
	ld	(%1),a
	and	a,%2
	ld	(%1),a
} by {
	and	a,%2
	ld	(%1),a
	; peephole z88dk-476c
}
// if notVolatile

replace restart {
	ld	(%1),a
	set	%2,a
	ld	(%1),a
} by {
	set	%2,a
	ld	(%1),a
	; peephole z88dk-476d
}
// if notVolatile

replace restart {
	ld	(%1),a
	res	%2,a
	ld	(%1),a
} by {
	res	%2,a
	ld	(%1),a
	; peephole z88dk-476e
}
// if notVolatile

replace restart {
	xor	a,#%1
	xor	a,#%2
} by {
	xor	a,#(%1^%2)
	; peephole z88dk-477a1
}

replace restart {
	xor	a,#%1
	xor	a,#(%2)
} by {
	xor	a,#(%1^%2)
	; peephole z88dk-477a2
}

replace restart {
	xor	a,#(%1)
	xor	a,#%2
} by {
	xor	a,#(%1^%2)
	; peephole z88dk-477a3
}

replace restart {
	xor	a,#(%1)
	xor	a,#(%2)
} by {
	xor	a,#(%1^%2)
	; peephole z88dk-477a4
}

replace restart {
	or	a,#%1
	or	a,#%2
} by {
	or	a,#(%1|%2)
	; peephole z88dk-477b1
}

replace restart {
	or	a,#%1
	or	a,#(%2)
} by {
	or	a,#(%1|%2)
	; peephole z88dk-477b2
}

replace restart {
	or	a,#(%1)
	or	a,#%2
} by {
	or	a,#(%1|%2)
	; peephole z88dk-477b3
}

replace restart {
	or	a,#(%1)
	or	a,#(%2)
} by {
	or	a,#(%1|%2)
	; peephole z88dk-477b2
}

replace restart {
	and	a,#%1
	and	a,#%2
} by {
	and	a,#(%1&%2)
	; peephole z88dk-477c1
}

replace restart {
	and	a,#%1
	and	a,#(%2)
} by {
	and	a,#(%1&%2)
	; peephole z88dk-477c2
}

replace restart {
	and	a,#(%1)
	and	a,#%2
} by {
	and	a,#(%1&%2)
	; peephole z88dk-477c3
}

replace restart {
	and	a,#(%1)
	and	a,#(%2)
} by {
	and	a,#(%1&%2)
	; peephole z88dk-477c4
}

replace restart {
	push	%1
	ld	%2,(%3)
} by {
	ld	%2,(%3)
	push	%1
	; peephole z88dk-478a
} if operandsNotRelated(%1 %2)

replace restart {
	ld	hl,#%1
	%2	a,%3
} by {
	%2	a,%3
	ld	hl,#%1
	; peephole z88dk-478b1
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%1 + %5
	%2	a,%3
} by {
	%2	a,%3
	ld	hl,#%1 + %5
	; peephole z88dk-478b1
} if operandsNotRelated(%3 'hl')

replace restart {
	ld	%1,%2
	%3	a
} by {
	%3	a
	ld	%1,%2
	; peephole z88dk-478c
} if operandsNotRelated(%1 'a'), operandsNotRelated(%2 'a')

replace restart {
	ex	de,hl
	ld	a,e
	ld	(bc),a
	inc	bc
	ld	a,d
	ld	(bc),a
} by {
	ld	a,l
	ld	(bc),a
	inc	bc
	ld	a,h
	ld	(bc),a
	ex	de,hl
	; peephole z88dk-478d
}

replace restart {
	ld	a,(#%1)
	ld	c,a
	ld	b,#%2
	sla	c
	rl	b
} by {
	ld	hl,(#%1)
	ld	h,#%2
	add	hl,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-479a
} if notUsed('a'), notUsed('hl')	

replace restart {
	ld	a,(#%1)
	ld	e,a
	ld	d,#%2
	sla	e
	rl	d
} by {
	ld	hl,(#%1)
	ld	h,#%2
	add	hl,hl
	ld	e,l
	ld	d,h
	; peephole z88dk-479b
} if notUsed('a'), notUsed('hl')	

replace restart {
	ld	bc,#%1
	ld	de,#%2
	ld	a,e
	ld	(bc),a
	inc	bc
	ld	a,d
	ld	(bc),a
} by {
	ld	de,#%2
	ld	(#%1),de
	ld	bc,#%1 + 1
	; peephole z88dk-480a
}

replace restart {
	ld	de,#%1
	ld	(#%2),de
} by {
	ld	hl,#%1
	ld	(#%2),hl
	; peephole z88dk-480b1
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	bc,#%1
	ld	(#%2),bc
} by {
	ld	hl,#%1
	ld	(#%2),hl
	; peephole z88dk-480b2
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	hl,(#%1)
	ld	c,l
	ld	b,h
} by {
	ld	bc,(#%1)
	; peephole z88dk-480c1
} if notUsed('hl')

replace restart {
	ld	hl,(#%1)
	ld	e,l
	ld	d,h
} by {
	ld	de,(#%1)
	; peephole z88dk-480c2
} if notUsed('hl')

replace restart {
	ld	hl,(#%1)
	ex	de,hl
} by {
	ld	de,(#%1)
	; peephole z88dk-480c3
} if notUsed('hl')

replace restart {
	push	af
	inc	sp
	push	bc
	inc	sp
} by {
	ld	c,b
	ld	b,a
	push	bc
	; peephole z88dk-481a1
} if notUsed('bc')

replace restart {
	push	af
	inc	sp
	push	de
	inc	sp
} by {
	ld	e,d
	ld	d,a
	push	de
	; peephole z88dk-481a2
} if notUsed('de')

replace restart {
	push	af
	inc	sp
	push	hl
	inc	sp
} by {
	ld	l,h
	ld	h,a
	push	hl
	; peephole z88dk-481a3
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	ld	hl,(#%1-1)
	ld	l,%2 (%3)
	push	hl
	; peephole z88dk-481b1
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	ld	a,(#%1)
	ld	d,a
	ld	e,%2 (%3)
	push	de
	; peephole z88dk-481b2
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	ld	a,(#%1)
	ld	b,a
	ld	c,%2 (%3)
	push	bc
	; peephole z88dk-481b3
} if notUsed('bc')

replace restart {
	push	de
	inc	sp
	push	bc
	inc	sp
} by {
	ld	e,b
	push	de
	; peephole z88dk-481c1
} if notUsed('e')

replace restart {
	push	de
	inc	sp
	push	hl
	inc	sp
} by {
	ld	e,h
	push	de
	; peephole z88dk-481c2
} if notUsed('e')

replace restart {
	push	bc
	inc	sp
	push	de
	inc	sp
} by {
	ld	c,d
	push	bc
	; peephole z88dk-481c3
} if notUsed('c')

replace restart {
	push	bc
	inc	sp
	push	hl
	inc	sp
} by {
	ld	c,h
	push	bc
	; peephole z88dk-481c4
} if notUsed('c')

replace restart {
	push	hl
	inc	sp
	push	bc
	inc	sp
} by {
	ld	l,b
	push	hl
	; peephole z88dk-481c5
} if notUsed('l')

replace restart {
	push	hl
	inc	sp
	push	de
	inc	sp
} by {
	ld	l,d
	push	hl
	; peephole z88dk-481c6
} if notUsed('l')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,(#%2)
	push	af
	inc	sp
} by {
	ld	hl,(#%2)
	ld	h,#%1
	push	hl
	; peephole z88dk-481d1
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,(#%2)
	push	af
	inc	sp
} by {
	ld	d,#%1
	ld	a,(#%2)
	ld	e,a
	push	de
	; peephole z88dk-481d2
} if notUsed('de')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,(#%2)
	push	af
	inc	sp
} by {
	ld	b,#%1
	ld	a,(#%2)
	ld	c,a
	push	bc
	; peephole z88dk-481d3
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	ld	a,(#%2)
	push	af
	inc	sp
} by {
	ld	hl,(#%1 - 1)
	ld	a,(#%2)
	ld	l,a
	push	hl
	; peephole z88dk-481e1
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	ld	a,(#%2)
	push	af
	inc	sp
} by {
	ld	de,(#%1 - 1)
	ld	a,(#%2)
	ld	e,a
	push	de
	; peephole z88dk-481e2
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	ld	a,(#%2)
	push	af
	inc	sp
} by {
	ld	bc,(#%1 - 1)
	ld	a,(#%2)
	ld	c,a
	push	bc
	; peephole z88dk-481e3
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	xor	a,a
	push	af
	inc	sp
} by {
	ld	hl,(#%1 - 1)
	xor	a,a
	ld	l,a
	push	hl
	; peephole z88dk-481f1
} if notUsed('hl')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	xor	a,a
	push	af
	inc	sp
} by {
	ld	de,(#%1 - 1)
	xor	a,a
	ld	e,a
	push	de
	; peephole z88dk-481f2
} if notUsed('de')

replace restart {
	ld	a,(#%1)
	push	af
	inc	sp
	xor	a,a
	push	af
	inc	sp
} by {
	ld	bc,(#%1 - 1)
	xor	a,a
	ld	c,a
	push	bc
	; peephole z88dk-481f3
} if notUsed('bc')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	l,(hl)
	ld	h,#%1
	ld	a,h
	push	hl
	; peephole z88dk-481g1
} if notUsed('hl')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	e,(hl)
	ld	d,#%1
	ld	a,d
	push	de
	; peephole z88dk-481g2
} if notUsed('de')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	c,(hl)
	ld	b,#%1
	ld	a,b
	push	bc
	; peephole z88dk-481g3
} if notUsed('bc')

replace restart {
	ld	b,a
	push	bc
	inc	sp
} by {
	push	af
	inc	sp
	; peephole z88dk-481h1
} if notUsed('b')

replace restart {
	ld	d,a
	push	de
	inc	sp
} by {
	push	af
	inc	sp
	; peephole z88dk-481h2
} if notUsed('d')

replace restart {
	ld	h,a
	push	hl
	inc	sp
} by {
	push	af
	inc	sp
	; peephole z88dk-481h3
} if notUsed('h')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	ld	h,#%1
	ld	l,%2 (%3)
	ld	a,l
	push	hl
	; peephole z88dk-481j1
} if notUsed('hl')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	ld	d,#%1
	ld	e,%2 (%3)
	ld	a,e
	push	de
	; peephole z88dk-481j2
} if notUsed('de')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,%2 (%3)
	push	af
	inc	sp
} by {
	ld	b,#%1
	ld	c,%2 (%3)
	ld	a,c
	push	bc
	; peephole z88dk-481j3
} if notUsed('bc')

replace restart {
	push	de
	inc	sp
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	e,(hl)
	ld	a,e
	push	de
	; peephole z88dk-481k1
} if notUsed('e')

replace restart {
	push	bc
	inc	sp
	ld	a,(hl)
	push	af
	inc	sp
} by {
	ld	c,(hl)
	ld	a,c
	push	bc
	; peephole z88dk-481k2
} if notUsed('c')

replace restart {
	push	bc
	inc	sp
	ld	a,%1 (%2)
	push	af
	inc	sp
} by {
	ld	c,%1 (%2)
	ld	a,c
	push	bc
	; peephole z88dk-481m1
} if notUsed('c')

replace restart {
	push	de
	inc	sp
	ld	a,%1 (%2)
	push	af
	inc	sp
} by {
	ld	e,%1 (%2)
	ld	a,e
	push	de
	; peephole z88dk-481m2
} if notUsed('e')

replace restart {
	push	hl
	inc	sp
	ld	a,%1 (%2)
	push	af
	inc	sp
} by {
	ld	l,%1 (%2)
	ld	a,l
	push	hl
	; peephole z88dk-481m3
} if notUsed('l')

replace restart {
	ld	a,%1 (%2)
	push	af
	inc	sp
	xor	a,a
	push	af
	inc	sp
} by {
	ld	h,%1 (%2)
	xor	a,a
	ld	l,a
	push	hl
	; peephole z88dk-481n1
} if notUsed('hl')

replace restart {
	ld	a,%1 (%2)
	push	af
	inc	sp
	xor	a,a
	push	af
	inc	sp
} by {
	ld	d,%1 (%2)
	xor	a,a
	ld	e,a
	push	de
	; peephole z88dk-481n2
} if notUsed('de')

replace restart {
	ld	a,%1 (%2)
	push	af
	inc	sp
	xor	a,a
	push	af
	inc	sp
} by {
	ld	b,%1 (%2)
	xor	a,a
	ld	c,a
	push	bc
	; peephole z88dk-481n3
} if notUsed('bc')

replace restart {
	ld	a,(hl)
	push	af
	inc	sp
	ld	a,%1 (%2)
	push	af
	inc	sp
} by {
	ld	h,(hl)
	ld	l,%1 (%2)
	ld	a,l
	push	hl
	; peephole z88dk-481o1
} if notUsed('hl')

replace restart {
	ld	a,(hl)
	push	af
	inc	sp
	ld	a,%1 (%2)
	push	af
	inc	sp
} by {
	ld	d,(hl)
	ld	e,%1 (%2)
	ld	a,e
	push	de
	; peephole z88dk-481o2
} if notUsed('de')

replace restart {
	ld	a,(hl)
	push	af
	inc	sp
	ld	a,%1 (%2)
	push	af
	inc	sp
} by {
	ld	b,(hl)
	ld	c,%1 (%2)
	ld	a,c
	push	bc
	; peephole z88dk-481o3
} if notUsed('bc')

replace restart {
	push	de
	inc	sp
	push	af
	inc	sp
} by {
	ld	e,a
	push	de
	; peephole z88dk-481p1
} if notUsed('e')

replace restart {
	push	bc
	inc	sp
	push	af
	inc	sp
} by {
	ld	c,a
	push	bc
	; peephole z88dk-481p2
} if notUsed('c')

replace restart {
	push	hl
	inc	sp
	push	af
	inc	sp
} by {
	ld	l,a
	push	hl
	; peephole z88dk-481p3
} if notUsed('l')

replace restart {
	push	af
	inc	sp
	ld	a,(#%1)
	push	af
	inc	sp
} by {
	ld	hl,(#%1)
	ld	h,a
	ld	a,l
	push	hl
	; peephole z88dk-481q1
} if notUsed('hl')

replace restart {
	push	af
	inc	sp
	ld	a,(#%1)
	push	af
	inc	sp
} by {
	ld	de,(#%1)
	ld	d,a
	ld	a,e
	push	de
	; peephole z88dk-481q2
} if notUsed('de')

replace restart {
	push	af
	inc	sp
	ld	a,(#%1)
	push	af
	inc	sp
} by {
	ld	bc,(#%1)
	ld	b,a
	ld	a,c
	push	bc
	; peephole z88dk-481q3
} if notUsed('bc')

replace restart {
	push	bc
	inc	sp
	ld	a,(#%1)
	push	af
	inc	sp
} by {
	ld	a,(#%1)
	ld	c,a
	push	bc
	; peephole z88dk-481r1
} if notUsed('c')

replace restart {
	push	bc
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	ld	c,#%1
	ld	a,c
	push	bc
	; peephole z88dk-481r2a
} if notUsed('c')

replace restart {
	push	bc
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	ld	l,#%1
	ld	h,b
	ld	a,l
	push	hl
	; peephole z88dk-481r2b
} if notUsed('hl')

replace restart {
	push	de
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	ld	e,#%1
	ld	a,e
	push	de
	; peephole z88dk-481r3a
} if notUsed('e')

replace restart {
	push	de
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	ld	l,#%1
	ld	h,d
	ld	a,l
	push	hl
	; peephole z88dk-481r3b
} if notUsed('hl')

replace restart {
	push	hl
	inc	sp
	ld	a,#%1
	push	af
	inc	sp
} by {
	ld	l,#%1
	ld	a,l
	push	hl
	; peephole z88dk-481r4
} if notUsed('l')

replace restart {
	ld	a,#%1
	push	af
	inc	sp
	ld	a,c
	push	af
	inc	sp
} by {
	ld	b,#%1
	push	bc
	ld	a,c
	; peephole z88dk-481r5
} if notUsed('b')

replace restart {
	cpl
} by {
	; peephole z88dk-482a
} if notUsed('a')

replace restart {
	ld	c,(hl)
	ld	b,#%1
	sla	c
	rl	b
	ld	hl,#%2
	add	hl,bc
} by {
	ld	l,(hl)
	ld	h,#%1
	add	hl,hl
	ld	bc,#%2
	add	hl,bc
	; peephole z88dk-483a
} if notUsed('bc')

replace restart {
	ld	(%1),hl
	ld	hl,%1
	ld	a,(hl)
	sub	a,#%2
	inc	hl
	ld	a,(hl)
	sbc	a,#%3
} by {
	ld	(%1),hl
	ld	a,l
	sub	a,#%2
	ld	a,h
	sbc	a,#%3
	ld	hl,#%1
	; peephole z88dk-483b
}

replace restart {
	inc	(hl)
	ld	%1,(hl)
} by {
	ld	%1,(hl)
	inc	%1
	ld	(hl),%1
	; peephole z88dk-484a
} if operandsNotRelated(%1 'hl')

replace restart {
	dec	(hl)
	ld	%1,(hl)
} by {
	ld	%1,(hl)
	dec	%1
	ld	(hl),%1
	; peephole z88dk-484b
} if operandsNotRelated(%1 'hl')

replace restart {
	ld	(hl),%1
	inc	%1
	ld	(hl),%1
} by {
	inc	%1
	ld	(hl),%1
	; peephole z88dk-484c1
}
// notVolatile

replace restart {
	ld	(hl),%1
	dec	%1
	ld	(hl),%1
} by {
	dec	%1
	ld	(hl),%1
	; peephole z88dk-484c2
}
// notVolatile

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%2)
	ld	h,%3
	ld	bc,#%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%2
	; peephole z88dk-485a1
} if operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,#<(%1 + %7)
	ld	hl,#%2
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1 + %7)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%2)
	ld	h,%3
	ld	bc,#%1+%7
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%2
	; peephole z88dk-485a2
} if operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,#<(%1)
	ld	hl,#%2 + %8
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%2+%8)
	ld	h,%3
	ld	bc,#%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%2+%8
	; peephole z88dk-485a3
} if operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,#<(%1 + %7)
	ld	hl,#%2 + %8
	add	a,(hl)
	ld	c,a
	ld	a,#>(%1 + %7)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%2+%8)
	ld	h,%3
	ld	bc,#%1+%7
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%2+%8
	; peephole z88dk-485a4
} if operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,(#%1)
	add	a,#<(%2)
	ld	c,a
	ld	a,#>(%2)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	h,%3
	ld	bc,#%2
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-485b1
} if notUsed('hl'), operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,(#%1)
	add	a,#<(%2 + %7)
	ld	c,a
	ld	a,#>(%2 + %7)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	h,%3
	ld	bc,#%2+%7
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-485b2
} if notUsed('hl'), operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,(#%1 + %8)
	add	a,#<(%2)
	ld	c,a
	ld	a,#>(%2)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%1+%8)
	ld	h,%3
	ld	bc,#%2
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-485b3
} if notUsed('hl'), operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	a,(#%1 + %8)
	add	a,#<(%2 + %7)
	ld	c,a
	ld	a,#>(%2 + %7)
	adc	a,%3
	ld	b,a
} by {
	ld	hl,(#%1+%8)
	ld	h,%3
	ld	bc,#%2+%7
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-485b4
} if notUsed('hl'), operandsNotRelated(%3 'a'), operandsNotRelated(%3 'c'), operandsNotRelated(%3 'hl')

replace restart {
	ld	c,l
	ld	b,h
	%1	%2,%3
} by {
	%1	%2,%3
	ld	c,l
	ld	b,h
	; peephole z88dk-485c1a
} if same(%1 'set' 'res'), operandsNotRelated(%3 'bc'), operandsNotRelated(%3 'hl')

replace restart {
	ld	c,l
	ld	b,h
	bit	%2,%3
} by {
	bit	%2,%3
	ld	c,l
	ld	b,h
	; peephole z88dk-485c1b
} if operandsNotRelated(%3 'bc')

replace restart {
	ld	hl,#%5
	%1	%2,%3
} by {
	%1	%2,%3
	ld	hl,#%5
	; peephole z88dk-485c2
} if same(%1 'set' 'res' 'bit'), operandsNotRelated(%3 'hl')

replace restart {
	ld	hl,#%5
	ld	(bc),a
} by {
	ld	(bc),a
	ld	hl,#%5
	; peephole z88dk-485c3
}

replace restart {
	ex	de,hl
	%1	%2,%3
} by {
	%1	%2,%3
	ex	de,hl
	; peephole z88dk-485c4
} if same(%1 'set' 'res' 'bit'), operandsNotRelated(%3 'de'), operandsNotRelated(%3 'hl')

replace restart {
	ld	bc,#%1
	ld	a,%2
	ld	(bc),a
} by {
	ld	hl,#%1
	ld	a,%2
	ld	(hl),a
	ld	c,l
	ld	b,h
	; peephole z88dk-485d1
} if notUsed('hl'), operandsNotRelated(%2 'bc'), operandsNotRelated(%2 'hl')

replace restart {
	ld	c,l
	ld	b,h
	ld	%1,%2
} by {
	ld	%1,%2
	ld	c,l
	ld	b,h
	; peephole z88dk-485d2
} if operandsNotRelated(%1 'bc'), operandsNotRelated(%1 'hl'), operandsNotRelated(%2 'bc')

replace restart {
	ld	%1,a
	inc	%1
	inc	%1
} by {
	add	a,#0x02
	ld	%1,a
	; peephole z88dk-485e1
} if notUsed('a')

replace restart {
	add	a,#%2
	ld	%1,a
	inc	%1
} by {
	add	a,#%2+1
	ld	%1,a
	; peephole z88dk-485e2
} if notUsed('a')

replace restart {
	ld	%1,a
	dec	%1
	dec	%1
} by {
	add	a,#-0x02
	ld	%1,a
	; peephole z88dk-485e3
} if notUsed('a')

replace restart {
	add	a,#%2
	ld	%1,a
	dec	%1
} by {
	add	a,#%2-1
	ld	%1,a
	; peephole z88dk-485e4
} if notUsed('a')

//replace restart {
//	add	a,#%1
//	add	a,#%2
//} by {
//	add	a,#%1+#%2
//	; peephole z88dk-485e5
//}
// carry flag state not preserved

replace restart {
	ld	hl,#%1
	ld	h,(hl)
} by {
	ld	hl,(#%1-1)
	; peephole z88dk-485e6
} if notUsed('l')

replace restart {
	inc	a
	inc	a
} by {
	add	a,#0x02
	; peephole z88dk-485e7
}

replace restart {
	add	a,#%1
	inc	a
} by {
	add	a,#%1+1
	; peephole z88dk-485e8
}

replace restart {
	dec	a
	dec	a
} by {
	add	a,#-0x02
	; peephole z88dk-485e9
}

replace restart {
	add	a,#%1
	dec	a
} by {
	add	a,#%1-1
	; peephole z88dk-485e10
}

replace restart {
	ld	%1,%2 (%3)
	ld	%4,%5
	sla	%1
	rl	%4
} by {
	ld	l,%2 (%3)
	ld	h,%5
	add	hl,hl
	ld	%1,l
	ld	%4,h
	; peephole z88dk-485e11
} if notUsed('hl'), operandsNotRelated(%1 'hl'), operandsNotRelated(%4 'hl'), notSame(%5 'l')

replace restart {
	ld	a,e
	ld	hl,#%1
	add	a,(hl)
	ld	c,a
	ld	a,d
	adc	a,%2
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	h,%2
	add	hl,de
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-485e12
} if notUsed('hl'), notSame(%2 'a' 'c'), operandsNotRelated(%2 'hl')

replace restart {
	ld	a,e
	ld	hl,#%1
	add	a,(hl)
	ld	e,a
	ld	a,d
	adc	a,%2
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	h,%2
	add	hl,de
	ld	a,h
	ld	e,l
	ld	d,h
	; peephole z88dk-485e13
} if notUsed('hl'), notSame(%2 'a' 'e'), operandsNotRelated(%2 'hl')

replace restart {
	ld	a,c
	ld	hl,#%1
	add	a,(hl)
	ld	e,a
	ld	a,b
	adc	a,%2
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	h,%2
	add	hl,bc
	ld	a,h
	ld	e,l
	ld	d,h
	; peephole z88dk-485e14
} if notUsed('hl'), notSame(%2 'a' 'e'), operandsNotRelated(%2 'hl')

replace restart {
	ld 	a,e
	add	a,l
	ld	e,a
	ld	a,d
	adc	a,#0x%1
	ld	d,a
} by {
	ld	h,#0x%1
	add	hl,de
	ld	a,h
	ex	de,hl
	; peephole z88dk-485e15
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	adc	a,e
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	d,a
} by {
	ld	hl,(#%1 + %2)
	adc	hl,de
	ex	de,hl
	ld	a,d
	ld	hl,#%1 + %2+1
	; peephole z88dk-485e16
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,c
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a,#%2
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	b,#%2
	add	hl,bc
	ld	a,h
	ex	de,hl
	ld	hl,#%1 + 1
	; peephole z88dk-485e17a
} if notUsed('b')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,c
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a,#%2
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	a,b
	ld	b,#%2
	add	hl,bc
	ld	b,a
	ld	a,h
	ex	de,hl
	; peephole z88dk-485e17b
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a,c
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	sbc	a,b
	ld	(hl),a
} by {
	ld	hl,(#%1)
	xor	a,a
	sbc	hl,bc
	ld	(#%1),hl
	; peephole z88dk-485e17c1
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	sub	a,e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	sbc	a,d
	ld	(hl),a
} by {
	ld	hl,(#%1)
	xor	a,a
	sbc	hl,de
	ld	(#%1),hl
	; peephole z88dk-485e17c2
} if notUsed('a'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#%4
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	c,%2 (%3)
	ld	b,#%4
	add	hl,bc
	ld	(#%1),hl
	; peephole z88dk-485e17d1
} if notUsed('a'), notUsed('bc'), notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,%2 (%3)
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#%4
	ld	(hl),a
} by {
	ld	hl,(#%1)
	ld	e,%2 (%3)
	ld	d,#%4
	add	hl,de
	ld	(#%1),hl
	; peephole z88dk-485e17d2
} if notUsed('a'), notUsed('de'), notUsed('hl')

replace restart {
	ld	a,(#%1 + %7)
	ld	c,l
	ld	b,h
	ld	hl,#%3 + %4
	sbc	a,(hl)
	ld	e,a
	ld	a,(#%1 + %8)
	inc	hl
	sbc	a,(hl)
	ld	d,a
} by {
	ld	c,l
	ld	b,h
	ld	hl,(#%1 + %7)
	ld	de,(#%3 + %4)
	sbc	hl,de
	ex	de,hl
	ld	a,d
	ld	hl,#%3 + %4 + 1
	; peephole z88dk-485e17e1
} if inSequence('1' %7 %8)

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	adc	a,#0x%3
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%4
	ld	d,a
} by {
	ld	hl,(#%1 + %2)
	ld	de,#0x%4%3
	adc	hl,de
	ex	de,hl
	ld	a,d
	ld	hl,#%1 + %2 + 1
	; peephole z88dk-485e17f1
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,e
	ld	%2 (%3),a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	%4 (%5),a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	%2 (%3),l
	ld	%4 (%5),h
	ld	a,h
	ld	hl,#%1 + 1
	; peephole z88dk-485e17g1
}

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	adc	a,#0x%3
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%4
	ld	(hl),a
} by {
	ld	hl,(#%1 + %2)
	ld	de,#0x%4%3
	adc	hl,de
	ld	(#%1 + %2),hl
	; peephole z88dk-485e17h1
} if notUsed('de'), notUsed('hl'), notUsed('a')

replace restart {
	ld	hl,#%1 + %2
	ld	a,(hl)
	adc	a,#0x%3
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%4
	ld	(hl),a
} by {
	ld	hl,(#%1 + %2)
	ld	bc,#0x%4%3
	adc	hl,bc
	ld	(#%1 + %2),hl
	; peephole z88dk-485e17h2
} if notUsed('bc'), notUsed('hl'), notUsed('a')

replace restart {
	ld	a,(#%1 + %2)
	adc	a,e
	ld	(#%3 + %4),a
	ld	a,(#%1 + %5)
	adc	a,d
	ld	(#%3 + %6),a
} by {
	ld	hl,(#%1 + %2)
	adc	hl,de
	ld	(#%3 + %4),hl
	ld	a,h
	; peephole z88dk-485e17h3
} if notUsed('hl'), inSequence('1' %2 %5), inSequence('1' %4 %6)

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,e
	ld	e,a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%2
	ld	d,a
} by {
	ld	hl,(#%1)
	ld	d,#0x%2
	add	hl,de
	ex	de,hl
	ld	a,d
	ld	hl,#%1 + 1
	; peephole z88dk-485e17h4
}

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,c
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,#0x%2
	ld	b,a
} by {
	ld	hl,(#%1)
	ld	b,#0x%2
	add	hl,bc
	ld	c,l
	ld	b,h
	ld	a,h
	; peephole z88dk-485e17h5
} if notUsed('hl')

replace restart {
	ld	hl,#%1
	ld	a,(hl)
	add	a,e
	ld	c,a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	b,a
} by {
	ld	hl,(#%1)
	add	hl,de
	ld	a,h
	ld	c,l
	ld	b,h
	ld	hl,#%1 + 1
	; peephole z88dk-485e18
}

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,%1
	add	hl,bc
} by {
	ld	bc,%1
	add	hl,bc
	; peephole z88dk-485e19
} if notUsed('bc')

replace restart {
	ld	a,(#%1)
	ld	c,a
	ld	b,%2
	ld	hl,#%3
	add	hl,bc
} by {
	ld	hl,(#%1)
	ld	h,%2
	ld	bc,#%3
	add	hl,bc
	; peephole z88dk-486a
} if notSame(%2 'a'), notSame(%2 'c'), operandsNotRelated(%2 'hl'), notUsed('bc'), notUsed('a')

replace restart {
	%5	%1,(hl)
	%2	%3,(hl)
} by {
	ld	a,(hl)
	%5	%1,a
	ld	(hl),a
	%2	%3,(hl)
	; peephole z88dk-486b1
} if same(%2 'set' 'res' 'bit'), same(%5 'set' 'res' 'bit'), notUsed('a')

replace restart {
	ld	(hl),a
	%5	%2,(hl)
} by {
	%5	%2,a
	ld	(hl),a
	; peephole z88dk-486b2
} if same(%5 'set' 'res'), notUsed('a')

replace restart {
	ld	(hl),%3
	bit	%2,(hl)
} by {
	bit	%2,%3
	ld	(hl),%3
	; peephole z88dk-486b3
} if same(%3 'a' 'b' 'c' 'd' 'e' 'h' 'l')
// if notVolatile

replace restart {
	res	0,a
} by {
	and	a,#0xfe
	; peephole z88dk-487a0
}

replace restart {
	res	1,a
} by {
	and	a,#0xfd
	; peephole z88dk-487a1
}

replace restart {
	res	2,a
} by {
	and	a,#0xfb
	; peephole z88dk-487a2
}

replace restart {
	res	3,a
} by {
	and	a,#0xf7
	; peephole z88dk-487a3
}

replace restart {
	res	4,a
} by {
	and	a,#0xef
	; peephole z88dk-487a4
}

replace restart {
	res	5,a
} by {
	and	a,#0xdf
	; peephole z88dk-487a5
}

replace restart {
	res	6,a
} by {
	and	a,#0xbf
	; peephole z88dk-487a6
}

replace restart {
	res	7,a
} by {
	and	a,#0x7f
	; peephole z88dk-487a7
}

replace restart {
	set	0,a
} by {
	or	a,#0x01
	; peephole z88dk-487b0
}

replace restart {
	set	1,a
} by {
	or	a,#0x02
	; peephole z88dk-487b1
}

replace restart {
	set	2,a
} by {
	or	a,#0x04
	; peephole z88dk-487b2
}

replace restart {
	set	3,a
} by {
	or	a,#0x08
	; peephole z88dk-487b3
}

replace restart {
	set	4,a
} by {
	or	a,#0x10
	; peephole z88dk-487b4
}

replace restart {
	set	5,a
} by {
	or	a,#0x20
	; peephole z88dk-487b5
}

replace restart {
	set	6,a
} by {
	or	a,#0x40
	; peephole z88dk-487b6
}

replace restart {
	set	7,a
} by {
	or	a,#0x80
	; peephole z88dk-487b7
}

replace restart {
	push	bc
	push	de
	ex	de,hl
	pop	hl
	pop	bc
} by {
	ex	de,hl
	; peephole z88dk-488
}

replace restart {
	ld	a,(%1 + %6)
	ld	hl,%2 + %8
	adc	a,(hl)
	ld	hl,%1 + %6
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,%2 + %9
	adc	a,(hl)
	ld	(%1 + %7),a
} by {
	ld	hl,(%1 + %6)
	ld	bc,(%2 + %8)
	adc	hl,bc
	ld	(%1 + %6),hl
	ld	a,h
	ld	hl,%2 + %9
	; peephole z88dk-489a1
} if notUsed('bc'), inSequence('1' %6 %7), inSequence('1' %8 %9)

replace restart {
	ld	a,(%1 + %6)
	ld	hl,%2 + %8
	adc	a,(hl)
	ld	hl,%1 + %6
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,%2 + %9
	adc	a,(hl)
	ld	(%1 + %7),a
} by {
	ld	hl,(%1 + %6)
	ld	de,(%2 + %8)
	adc	hl,de
	ld	(%1 + %6),hl
	ld	a,h
	ld	hl,%2 + %9
	; peephole z88dk-489a2
} if notUsed('de'), inSequence('1' %6 %7), inSequence('1' %8 %9)

replace restart {
	ld	a,(%1 + %6)
	ld	hl,%2 + %8
	adc	a,(hl)
	ld	hl,%1 + %6
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	ld	hl,%2 + %9
	adc	a,(hl)
	ld	(%1 + %7),a
} by {
	push	bc
	ld	hl,(%1 + %6)
	ld	bc,(%2 + %8)
	adc	hl,bc
	pop	bc
	ld	(%1 + %6),hl
	ld	a,h
	ld	hl,%2 + %9
	; peephole z88dk-489a3
} if inSequence('1' %6 %7), inSequence('1' %8 %9)

replace restart {
	ld	hl,%1 + %2
	ld	a,(hl)
	adc	a,e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	(hl),a
} by {
	ld	hl,(%1 + %2)
	adc	hl,de
	ld	(%1 + %2),hl
	ld	a,h
	; peephole z88dk-489b1
} if notUsed('hl')

replace restart {
	ld	hl,%1 + %2
	ld	a,(hl)
	add	a,e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	(hl),a
} by {
	ld	hl,(%1 + %2)
	add	hl,de
	ld	(%1 + %2),hl
	ld	a,h
	; peephole z88dk-489b2
} if notUsed('hl')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1)
	ld	de,(#%2)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1)
	ld	bc,(#%2)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b3a
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1 + %3)
	ld	de,(#%2)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1 + %3)
	ld	bc,(#%2)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b3b
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1)
	ld	de,(#%2 + %4)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1)
	ld	bc,(#%2 + %4)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b3c
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1 + %3)
	ld	de,(#%2 + %4)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1 + %3)
	ld	bc,(#%2 + %4)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b3d
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	ld	de,#%2
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	ld	bc,#%2
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b4a
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %3
	ld	de,#%2
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1 + %3
	ld	bc,#%2
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b4b
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	ld	de,#%2 + %4
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	ld	bc,#%2 + %4
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b4c
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %3
	ld	de,#%2 + %4
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1 + %3
	ld	bc,#%2 + %4
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b4d
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1)
	ld	de,#%2
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1)
	ld	bc,#%2
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b5a
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1 + %3)
	ld	de,#%2
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1 + %3)
	ld	bc,#%2
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b5b
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1)
	ld	de,#%2 + %4
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1)
	ld	bc,#%2 + %4
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b5c
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,(#%1 + %3)
	ld	de,#%2 + %4
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,(#%1 + %3)
	ld	bc,#%2 + %4
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b5d
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	ld	de,(#%2)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	ld	bc,(#%2)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b6a
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %3
	ld	de,(#%2)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1 + %3
	ld	bc,(#%2)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b6b
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1
	ld	de,(#%2 + %4)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1
	ld	bc,(#%2 + %4)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b6c
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	c,l
	ld	b,h
	ld	hl,#%1 + %3
	ld	de,(#%2 + %4)
	%6	hl,de
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	ld	hl,#%1 + %3
	ld	bc,(#%2 + %4)
	%6	hl,bc
	ex	de,hl
	ld	c,l
	ld	b,h
	; peephole z88dk-489b6d
} if same(%6 'add' 'adc' 'sbc')

replace restart {
	ld	a,(%1)
	ld	hl,%2
	%10	a,(hl)
	ld	%6 (ix),a
	ld	a,(%1 + 1)
	ld	hl,%2 + 1
	%10	a,(hl)
	ld	%7 (ix),a
	ld	a,(%1 + 2)
	ld	hl,%2 + 2
	%10	a,(hl)
	ld	%8 (ix),a
	ld	a,(%1 + 3)
	ld	hl,%2 + 3
	%10	a,(hl)
	ld	%9 (ix),a
} by {
	ld	a,(%1)
	ld	hl,%2
	%10	a,(hl)
	ld	%6 (ix),a
	ld	a,(%1 + 1)
	inc	hl
	%10	a,(hl)
	ld	%7 (ix),a
	ld	a,(%1 + 2)
	inc	hl
	%10	a,(hl)
	ld	%8 (ix),a
	ld	a,(%1 + 3)
	inc	hl
	%10	a,(hl)
	ld	%9 (ix),a
	; peephole z88dk-489c1
} if same(%10 'or' 'and' 'xor')

replace restart {
	ld	a,(%1)
	ld	hl,%2
	%10	a,(hl)
	ld	c,a
	ld	a,(%1 + 1)
	ld	hl,%2 + 1
	%10	a,(hl)
	ld	b,a
	ld	a,(%1 + 2)
	ld	hl,%2 + 2
	%10	a,(hl)
	ld	e,a
	ld	a,(%1 + 3)
	ld	hl,%2 + 3
	%10	a,(hl)
	ld	d,a
} by {
	ld	a,(%1)
	ld	hl,%2
	%10	a,(hl)
	ld	c,a
	ld	a,(%1 + 1)
	inc	hl
	%10	a,(hl)
	ld	b,a
	ld	a,(%1 + 2)
	inc	hl
	%10	a,(hl)
	ld	e,a
	ld	a,(%1 + 3)
	inc	hl
	%10	a,(hl)
	ld	d,a
	; peephole z88dk-489c2
} if same(%10 'or' 'and' 'xor')

replace restart {
	ld	a,c
	ld	hl,%1
	%10	a,(hl)
	ld	c,a
	ld	a,b
	inc	hl
	%10	a,(hl)
	ld	b,a
	ld	a,e
	inc	hl
	%10	a,(hl)
	ld	e,a
	ld	a,d
	inc	hl
	%10	a,(hl)
	ld	d,a
} by {
	ld	hl,(%1)
	ld	a,c
	%10	a,l
	ld	c,a
	ld	a,b
	%10	a,h
	ld	b,a
	ld	hl,(%1 + 2)
	ld	a,e
	%10	a,l
	ld	e,a
	ld	a,d
	%10	a,h
	ld	d,a
	ld	hl,%1 + 3
	; peephole z88dk-489d1
} if same(%10 'and' 'or' 'xor')

replace restart {
	ld	a,c
	%10	a,%6 (ix)
	ld	hl,%1
	ld	(hl),a
	ld	a,b
	%10	a,%7 (ix)
	inc	hl
	ld	(hl),a
	ld	a,e
	%10	a,%8 (ix)
	inc	hl
	ld	(hl),a
	ld	a,d
	%10	a,%9 (ix)
	inc	hl
	ld	(hl),a
} by {
	ld	a,c
	%10	a,%6 (ix)
	ld	l,a
	ld	a,b
	%10	a,%7 (ix)
	ld	h,a
	ld	(%1),hl
	ld	a,e
	%10	a,%8 (ix)
	ld	l,a
	ld	a,d
	%10	a,%9 (ix)
	ld	h,a
	ld	(%1 + 2),hl
	ld	hl,%1 + 3
	; peephole z88dk-489d2
} if same(%10 'and' 'or' 'xor')

replace restart {
	ld	a,c
	add	a,(hl)
	ld	c,a
	ld	a,b
	adc	a,#0x%1
	ld	b,a
} by {
	ld	l,(hl)
	ld	h,#0x%1
	add	hl,bc
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-490a1
} if notUsed('hl')

replace restart {
	ld	a,e
	add	a,(hl)
	ld	e,a
	ld	a,d
	adc	a,#0x%1
	ld	d,a
} by {
	ld	l,(hl)
	ld	h,#0x%1
	add	hl,de
	ex	de,hl
	ld	a,d
	; peephole z88dk-490a2
} if notUsed('hl')

replace restart
{
	ld	hl,#%1
	%2	%3,(hl)
	jp	%4,%5
	ld	hl,#%1
} by {
	ld	hl,#%1
	%2	%3,(hl)
	jp	%4,%5
	; peephole z88dk-491a1
} if same(%2 'bit' 'set' 'res')

replace restart {
	ld	hl,#%1
	%2	%3,(hl)
	jp	%4,%5
	%6	%7,(hl)
	jp	%8,%9
	ld	hl,#%1
} by {
	ld	hl,#%1
	%2	%3,(hl)
	jp	%4,%5
	%6	%7,(hl)
	jp	%8,%9
	; peephole z88dk-491a2
} if same(%2 'bit' 'set' 'res'), same(%6 'bit' 'set' 'res')

// multiplication by minus one

replace restart {
	ld	%1,l
	ld	%2,h
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
	add	hl,hl
	add	hl,%2%1
} by {
	ld	%1,l
	ld	%2,h
	ld	a,l
	cpl
	ld	l,a
	ld	a,h
	cpl
	ld	h,a
	inc	hl
	; peephole z88dk-492a1
} if notUsed('a')

replace restart {
	ld	a,l
	ld	l,h
	ld	h,a
	ld	a,l
	ld	l,h
	ld	h,a
} by {
	ld a,h
	; peephole z88dk-492b1
}

replace restart {
	ld	a,l
	ld	l,h
	ld	h,a
	ex	de,hl
} by {
	ex	de,hl
	ld	a,e
	ld	e,d
	ld	d,a
	; peephole z88dk-492b2
}

replace restart {
	ld	a,d
	ld	d,l
	ld	l,a
	ld	a,e
	ld	e,h
	ld	h,a
	ld	a,d
	ld	d,l
	ld	l,a
	ld	a,e
	ld	e,h
	ld	h,a
} by {
	ld	a,h
	; peephole z88dk-492b3
}

replace restart {
	ex	de,hl
	ld	de,#%1
	ex	de,hl
} by {
	ld	hl,#%1
	; peephole z88dk-492c1
}

replace restart {
	ex	de,hl
	ld	de,#%1 + %2
	ex	de,hl
} by {
	ld	hl,#%1 + %2
	; peephole z88dk-492c2
}

replace restart {
	ex	de,hl
	ld	hl,#%1
	ex	de,hl
} by {
	ld	de,#%1
	; peephole z88dk-492c3
}

replace restart {
	ex	de,hl
	ld	hl,#%1 + %2
	ex	de,hl
} by {
	ld	de,#%1 + %2
	; peephole z88dk-492c4
}

replace restart {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	%7,%8 (%9)
	ld	%10,%11 (%12)
	ld	%2 (%3),%1
	ld	%5 (%6),%4
	ld	%8 (%9),%7
	ld	%11 (%12),%10
} by {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	%7,%8 (%9)
	ld	%10,%11 (%12)
   ; peephole z88dk-492d1a
} if notSame(%1 %4 %7 %10), notSame(%4 %7 %10), notSame(%7 %10), notSame(%2 %5 %8 %11), notSame(%5 %8 %11), notSame(%8 %11)

replace restart {
	ld	%2 (%3),%1
	ld	%5 (%6),%4
	ld	%8 (%9),%7
	ld	%11 (%12),%10
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	%7,%8 (%9)
	ld	%10,%11 (%12)
} by {
	ld	%2 (%3),%1
	ld	%5 (%6),%4
	ld	%8 (%9),%7
	ld	%11 (%12),%10
   ; peephole z88dk-492d1b
} if notSame(%1 %4 %7 %10), notSame(%4 %7 %10), notSame(%7 %10), notSame(%2 %5 %8 %11), notSame(%5 %8 %11), notSame(%8 %11)

replace restart {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	ld	%2 (%3),%1
	ld	%5 (%6),%4
} by {
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
	; peephole z88dk-492d2a
} if notSame(%1 %4), notSame(%2 %5)

replace restart {
	ld	%2 (%3),%1
	ld	%5 (%6),%4
	ld	%1,%2 (%3)
	ld	%4,%5 (%6)
} by {
	ld	%2 (%3),%1
	ld	%5 (%6),%4
	; peephole z88dk-492d2b
} if notSame(%1 %4), notSame(%2 %5)

replace restart {
	push	de
	pop	hl
} by {
	ld	l,e
	ld	h,d
	; peephole z88dk-493a1
}

replace restart {
	push	bc
	pop	hl
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-493a2
}

replace restart {
	push	bc
	pop	de
} by {
	ld	e,c
	ld	d,b
	; peephole z88dk-493a3
}

replace restart {
	push	de
	pop	bc
} by {
	ld	c,e
	ld	b,d
	; peephole z88dk-493a4
}

replace restart {
	push	hl
	pop	bc
} by {
	ld	c,l
	ld	b,h
	; peephole z88dk-493a5
}

replace restart {
	push	hl
	pop	de
} by {
	ld	e,l
	ld	d,h
	; peephole z88dk-493a6
}

replace restart {
	push	%1
	pop	%1
} by {
	; peephole z88dk-493a7
}

replace restart {
	ld	hl,#%1
	ld	l,(hl)
	ld	h,#%2
} by {
	ld	hl,(#%1)
	ld	h,#%2
	; peephole z88dk-494a1
}

replace restart {
	ld	hl,#%1 + %3
	ld	l,(hl)
	ld	h,#%2
} by {
	ld	hl,(#%1 + %3)
	ld	h,#%2
	; peephole z88dk-494a2
}

replace restart {
	ld	bc,(#%1)
	ld	d,b
	ld	hl,#%1
	ld	e,(hl)
} by {
	ld	bc,(#%1)
	ld	e,c
	ld	d,b
	ld	hl,#%1
	; peephole z88dk-494a3
}

replace restart {
	ld	l,c
	ld	h,b
	ld	a,d
	ld	d,l
	ld	l,a
	ld	a,e
	ld	e,h
	ld	h,a
} by {
	ld	a,d
	ld	d,c
	ld	l,a
	ld	a,e
	ld	e,b
	ld	h,a
	; peephole z88dk-494a4
}









replace restart {
	z88dk_sll hl,0x01+1
} by {
	add	hl,hl
	; peephole z88dk-500a
}

replace restart {
	z88dk_sll hl,0x02+1
} by {
	add	hl,hl
	add	hl,hl
	; peephole z88dk-500b
}

replace restart {
	z88dk_sll hl,0x03+1
} by {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	; peephole z88dk-500c
}

replace restart {
	z88dk_sll hl,0x04+1
} by {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	; peephole z88dk-500d
}

replace restart {
	z88dk_sll hl,0x05+1
} by {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	; peephole z88dk-500e
}

replace restart {
	z88dk_sll hl,0x06+1
} by {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	; peephole z88dk-500f
}

replace restart {
	z88dk_sll hl,0x07+1
} by {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	; peephole z88dk-500g
}

replace restart {
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
} by {
	xor	a,a
	add	hl,hl
	rla
	ld	l,h
	ld	h,a
	; peephole z88dk-501f
} if notUsed('a')

replace restart {
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
} by {
	xor	a,a
	add	hl,hl
	rla
	add	hl,hl
	rla
	ld	l,h
	ld	h,a
	; peephole z88dk-501e
} if notUsed('a')

replace restart {
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
	srl	h
	rr	l
} by {
	xor	a,a
	add	hl,hl
	rla
	add	hl,hl
	rla
	add	hl,hl
	rla
	ld	l,h
	ld	h,a
	; peephole z88dk-501d
} if notUsed('a')

replace restart {
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
} by {
	rl	e
	rl	d
	sbc	a,a
	ld	e,d
	ld	d,a
	; peephole z88dk-502f
} if notUsed('a')

replace restart {
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
} by {
	ex	de,hl
	add	hl,hl
	sbc	a,a
	add	hl,hl
	rla
	ld	e,h
	ld	d,a
	; peephole z88dk-502e1
} if notUsed('a'), notUsed('hl')

replace restart {
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
} by {
	ex	de,hl
	add	hl,hl
	sbc	a,a
	add	hl,hl
	rla
	ex	de,hl
	ld	e,d
	ld	d,a
	; peephole z88dk-502e2
} if notUsed('a')

replace restart {
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
} by {
	ex	de,hl
	add	hl,hl
	sbc	a,a
	add	hl,hl
	rla
	add	hl,hl
	rla
	ld	e,h
	ld	d,a
	; peephole z88dk-502d1
} if notUsed('a'), notUsed('hl')

replace restart {
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
	sra	d
	rr	e
} by {
	ex	de,hl
	add	hl,hl
	sbc	a,a
	add	hl,hl
	rla
	add	hl,hl
	rla
	ex	de,hl
	ld	e,d
	ld	d,a
	; peephole z88dk-502d2
} if notUsed('a')

replace restart {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
} by {
	ld	h,l
	ld	l,#0x00
	; peephole z88dk-503a
}

replace restart {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
} by {
	xor	a,a
	srl	h
	rr	l
	rra
	ld	h,l
	ld	l,a
	; peephole z88dk-503b1
} if notUsed('a')

replace restart {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
} by {
	srl	h
	rr	l
	ld	h,l
	ld	l,0
	rr	l
	; peephole z88dk-503b2
}

replace restart {
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
} by {
	xor	a,a
	srl	h
	rr	l
	rra
	srl	h
	rr	l
	rra
	ld	h,l
	ld	l,a
	; peephole z88dk-503c
} if notUsed('a')

replace restart {
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
} by {
	add	hl,hl
	sbc	a,a
	ld	l,h
	ld	h,a
	; peephole z88dk-504f
} if notUsed('a')

replace restart {
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
} by {
	add	hl,hl
	sbc	a,a
	add	hl,hl
	rla
	ld	l,h
	ld	h,a
	; peephole z88dk-504e
} if notUsed('a')

replace restart {
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
	sra	h
	rr	l
} by {
	add	hl,hl
	sbc	a,a
	add	hl,hl
	rla
	add	hl,hl
	rla
	ld	l,h
	ld	h,a
	; peephole z88dk-504d
} if notUsed('a')

replace restart {
	sra	%1
	rr	%2
	sra	%1
	rr	%2
	sra	%1
	rr	%2
} by {
	ld	a,%2
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	ld	%2,a
	; peephole z88dk-505a
} if notUsed('a')

replace restart {
	ld	%2,a
	sra	%1
	rr	%2
} by {
	sra	%1
	rra
	ld	%2,a
	; peephole z88dk-505b
} if notUsed('a')

replace restart {
	srl	%1
	rr	%2
	srl	%1
	rr	%2
	srl	%1
	rr	%2
} by {
	ld	a,%2
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	ld	%2,a
	; peephole z88dk-506a
} if notUsed('a')

replace restart {
	ld	%2,a
	srl	%1
	rr	%2
} by {
	srl	%1
	rra	
	ld	%2,a
	; peephole z88dk-506b
} if notUsed('a')

replace restart {
	sla	l
	rl	h
} by {
	add	hl,hl
	; peephole z88dk-507aa
}

replace restart {
	sla	%1
	rl	%2
	sla	%1
	rl	%2
	sla	%1
	rl	%2
} by {
	ld	a,%2
	sla	%1
	rla
	sla	%1
	rla
	sla	%1
	rla
	ld	%2,a
	; peephole z88dk-507a
} if notUsed('a')

replace restart {
	ld	%2,a
	sla	%1
	rl	%2
} by {
	sla	%1
	rla
	ld	%2,a
	; peephole z88dk-507b
} if notUsed('a')

















replace restart {
	ld	hl,#%1
	ld	de,#%2
} by {
	ld	de,#%2
	ld	hl,#%1
	; peephole z88dk-600a
}

replace restart {
	ld	hl,#%1 + %3
	ld	de,#%2
} by {
	ld	de,#%2
	ld	hl,#%1 + %3
	; peephole z88dk-600b
}

replace restart {
	ld	hl,#%1
	ld	de,(#%2)
} by {
	ld	de,(#%2)
	ld	hl,#%1
	; peephole z88dk-600c
}

replace restart {
	ld	hl,#%1 + %3
	ld	de,(#%2)
} by {
	ld	de,(#%2)
	ld	hl,#%1 + %3
	; peephole z88dk-600d
}

replace restart {
	ld	hl,#%1
	ld	de,(#%2 + %4)
} by {
	ld	de,(#%2 + %4)
	ld	hl,#%1
	; peephole z88dk-600e
}

replace restart {
	ld	hl,#%1 + %3
	ld	de,(#%2 + %4)
} by {
	ld	de,(#%2 + %4)
	ld	hl,#%1 + %3
	; peephole z88dk-600f
}

replace restart {
	ld	l,e
	ld	h,d
} by {
	ex	de,hl
	; peephole z88dk-601a
} if notUsed('de')

replace restart {
	ld	e,l
	ld	d,h
} by {
	ex	de,hl
	; peephole z88dk-601b
} if notUsed('hl')

replace restart {
	or	a,%1
	or	a,a
} by {
	or	a,%1
	; peephole z88dk-602a
}

replace restart {
	or	a,%1
	jp	%2,%3
	or	a,a
} by {
	or	a,%1
	jp	%2,%3
	; peephole z88dk-602b
}

replace restart {
	ex	de,hl
	ex	de,hl
} by {
	; peephole z88dk-603a1
}

replace restart {
	ex	de,hl
	%1	a,a
	ex	de,hl
} by {
	%1	a,a
	; peephole z88dk-603a2
}

replace restart {
	ex	de,hl
} by {
	; peephole z88dk-603b
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	ld	l,e
	ld	h,d
} by {
	ld	e,l
	ld	d,h
	; peephole z88dk-603c
}

replace restart {
	ld	l,e
	ld	h,d
	ex	de,hl
} by {
	ld	l,e
	ld	h,d
	; peephole z88dk-603d
}

replace restart {
	ld	e,l
	ld	d,h
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	; peephole z88dk-603e
}

replace restart {
	ld	l,e
	ld	h,d
} by {
	ex	de,hl
	; peephole z88dk-603f
} if notUsed('de')

replace restart {
	ld	h,d
	ld	l,e
} by {
	ex	de,hl
	; peephole z88dk-603g
} if notUsed('de')

replace restart {
	ld	e,l
	ld	d,h
} by {
	ex	de,hl
	; peephole z88dk-603h
} if notUsed('hl')

replace restart {
	ld	d,h
	ld	e,l
} by {
	ex	de,hl
	; peephole z88dk-603i
} if notUsed('hl')

replace restart {
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-603j
} if notUsed('de')

replace restart {
	ld	de,%1
	ld	hl,%2
	ex	de,hl
} by {
	ld	de,%2
	ld	hl,%1
	; peephole z88dk-603k1
}

replace restart {
	ld	de,%1 + %3
	ld	hl,%2
	ex	de,hl
} by {
	ld	de,%2
	ld	hl,%1 + %3
	; peephole z88dk-603k2
}

replace restart {
	ld	de,%1
	ld	hl,%2 + %4
	ex	de,hl
} by {
	ld	de,%2 + %4
	ld	hl,%1
	; peephole z88dk-603k3
}

replace restart {
	ld	de,%1 + %3
	ld	hl,%2 + %4
	ex	de,hl
} by {
	ld	de,%2 + %4
	ld	hl,%1 + %3
	; peephole z88dk-603k4
}

replace restart {
	ld	e,%1 (%2)
	ld	d,%3 (%4)
	%5	a
	ex	de,hl
} by {
	ex	de,hl
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	%5	a
	; peephole z88dk-603l
}

replace restart {
	ex	de,hl
	ld	a,%1
} by {
	ld	a,%1
	ex	de,hl
	; peephole z88dk-603m
} if operandsNotRelated(%1 'de'), operandsNotRelated(%1 'hl')

replace restart {
	ex	de,hl
	%1	de
	ld	(de),a
} by {
	%1	hl
	ld	(hl),a
	ex	de,hl
	; peephole z88dk-603n
}

replace restart {
	ld	%1,#%2 + 1
	dec	%1
} by {
	ld	%1,#%2
	; peephole z88dk-604a
}

replace restart {
	ld	%1,#%2 - 1
	inc	%1
} by {
	ld	%1,#%2
	; peephole z88dk-604b
}

replace restart {
	ex	de,hl
	ld	a,(de)
} by {
	ld	a,(hl)
	ex	de,hl
	; peephole z88dk-605a
}

replace restart {
	inc	de
	ex	de,hl
} by {
	ex	de,hl
	inc	hl
	; peephole z88dk-605b
}

replace restart {
	dec	de
	ex	de,hl
} by {
	ex	de,hl
	dec	hl
	; peephole z88dk-605c
}

replace restart {
	inc	hl
	ex	de,hl
} by {
	ex	de,hl
	inc	de
	; peephole z88dk-605d
}

replace restart {
	dec	hl
	ex	de,hl
} by {
	ex	de,hl
	dec	de
	; peephole z88dk-605e
}

replace restart {
	ex	de,hl
	push	hl
} by {
	push	de
	ex	de,hl
	; peephole z88dk-605f
}

replace restart {
	ex	de,hl
	push	de
} by {
	push	hl
	ex	de,hl
	; peephole z88dk-605g
}

replace restart {
	ex	de,hl
	ld	(%1 + %2),de
} by {
	ld	(%1 + %2),hl
	ex	de,hl
	; peephole z88dk-605h
}

replace restart {
	ex	de,hl
	ld	(%1),de
} by {
	ld	(%1),hl
	ex	de,hl
	; peephole z88dk-605i
}

replace restart {
	ex	de,hl
	ld	(%1),bc
	ld	(%2),de
} by {
	ld	(%1),bc
	ld	(%2),hl
	ex	de,hl
	; peephole z88dk-605j
}

replace restart {
	ex	de,hl
	ld	(%1),bc
	ld	(%2 + %4),de
} by {
	ld	(%1),bc
	ld	(%2 + %4),hl
	ex	de,hl
	; peephole z88dk-605k
}

replace restart {
	ex	de,hl
	ld	(%1 + %3),bc
	ld	(%2 + %4),de
} by {
	ld	(%1 + %3),bc
	ld	(%2 + %4),hl
	ex	de,hl
	; peephole z88dk-605l
}

replace restart {
	ex	de,hl
	ld	(%1 + %3),bc
	ld	(%2 + %4 + %6),de
} by {
	ld	(%1 + %3),bc
	ld	(%2 + %4 + %6),hl
	ex	de,hl
	; peephole z88dk-605m
}

replace restart {
	ex	de,hl
	ld	c,e
	ld	b,d
	ld	(%1),de
} by {
	ld	c,l
	ld	b,h
	ld	(%1),hl
	ex	de,hl
	; peephole z88dk-605n
}

replace restart {
	ld	hl,#%1
	ex	de,hl
} by {
	ex	de,hl
	ld	de,#%1
	; peephole z88dk-605o1
}

replace restart {
	ld	hl,#%1 + %2
	ex	de,hl
} by {
	ex	de,hl
	ld	de,#%1 + %2
	; peephole z88dk-605o2
}

replace restart {
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	ex	de,hl
} by {
	ex	de,hl
	ld	e,%1 (%2)
	ld	d,%3 (%4)
	; peephole z88dk-605p1
}

replace restart {
	ld	e,%1 (%2)
	ld	d,%3 (%4)
	ex	de,hl
} by {
	ex	de,hl
	ld	l,%1 (%2)
	ld	h,%3 (%4)
	; peephole z88dk-605p2
}

replace restart {
	ex	de,hl
	ld	c,e
	ld	b,d
} by {
	ld	c,l
	ld	b,h
	; peephole z88dk-605q
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	ld	hl,(%1)
	xor	a,a
	ex	de,hl
} by {
	ld	de,(%1)
	xor	a,a
	; peephole z88dk-605r1
}

replace restart {
	ex	de,hl
	ld	hl,(%1 + %2)
	xor	a,a
	ex	de,hl
} by {
	ld	de,(%1 + %2)
	xor	a,a
	; peephole z88dk-605r1
}

replace restart {
	ld	(#%1 + %2),hl
	ld	hl,(#%3)
	ld	de,(#%1 + %2)
} by {
	ld	(#%1 + %2),hl
	ex	de,hl
	ld	hl,(#%3)
	; peephole z88dk-605s1
}

replace restart {
	ld	(#%1),hl
	ld	hl,(#%3)
	ld	de,(#%1)
} by {
	ld	(#%1),hl
	ex	de,hl
	ld	hl,(#%3)
	; peephole z88dk-605s2
}

replace restart {
	ld	(#%1 + %2),hl
	ld	hl,(#%3 + %4)
	ld	de,(#%1 + %2)
} by {
	ld	(#%1 + %2),hl
	ex	de,hl
	ld	hl,(#%3 + %4)
	; peephole z88dk-605s3
}

replace restart {
	ld	(#%1),hl
	ld	hl,(#%3 + %4)
	ld	de,(#%1)
} by {
	ld	(#%1),hl
	ex	de,hl
	ld	hl,(#%3 + %4)
	; peephole z88dk-605s4
}

replace restart {
	ld	e,l
	ld	d,h
	xor	a,a
	ex	de,hl
} by {
	ld	e,l
	ld	d,h
	xor	a,a
	; peephole z88dk-605t1
}

replace restart {
	ld	l,e
	ld	h,d
	xor	a,a
	ex	de,hl
} by {
	ld	l,e
	ld	h,d
	xor	a,a
	; peephole z88dk-605t2
}

replace restart {
	ex	de,hl
	xor	a,a
	ex	de,hl
} by {
	xor	a,a
	; peephole z88dk-605t3
}

replace restart {
	ld	l,e
	ld	h,d
	ex	de,hl
} by {
	; peephole z88dk-605u1
}

replace restart {
	ld	e,l
	ld	d,h
	ex	de,hl
} by {
	; peephole z88dk-605u2
}

replace restart {
	ld	e,c
	ld	d,b
	ex	de,hl
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-605u3
} if notUsed('de')

replace restart {
	ld	l,c
	ld	h,b
	ex	de,hl
} by {
	ld	e,c
	ld	d,b
	; peephole z88dk-605u3
} if notUsed('hl')

replace restart {
	ld	e,%2
	ld	d,#%1
	ex	de,hl
} by {
	ld	l,%2
	ld	h,#%1
	; peephole z88dk-605v
} if notUsed('de')

replace restart {
	push	bc
	ex	de,hl
	pop	bc
} by {
	ex	de,hl
	; peephole z88dk-605w
}

replace restart {
	ex	de,hl
	ld	d,%1
} by {
	ld	h,%1
	ex	de,hl
	; peephole z88dk-606v1
} if operandsNotRelated(%1 'de'), operandsNotRelated(%1 'hl')

replace restart {
	ex	de,hl
	ld	e,%1
} by {
	ld	l,%1
	ex	de,hl
	; peephole z88dk-606v2
} if operandsNotRelated(%1 'de'), operandsNotRelated(%1 'hl')

replace restart {
	ex	de,hl
	ld	h,%1
} by {
	ld	d,%1
	ex	de,hl
	; peephole z88dk-606v1
} if operandsNotRelated(%1 'de'), operandsNotRelated(%1 'hl')

replace restart {
	ex	de,hl
	ld	l,%1
} by {
	ld	e,%1
	ex	de,hl
	; peephole z88dk-606v2
} if operandsNotRelated(%1 'de'), operandsNotRelated(%1 'hl')

replace restart {
	ld	a,c
	ld	(de),a
	inc	de
	ld	a,b
	ld	(de),a
} by {
	ex	de,hl
	ld	(hl),c
	inc	hl
	ld	(hl),b
	ex	de,hl
	ld	a,b
	; peephole z88dk-606w
}

replace restart {
	ld	%1,%2
	ld	%2,%1
} by {
	ld	%1,%2
	; peephole z88dk-606a1
} if notSame(%1 %2)
// notVolatile

replace restart {
	ld	a,h
	ld	d,a
} by {
	ld	a,h
	ld	d,h
	; peephole z88dk-606a2
}
// more general slows peephole considerably

replace restart {
	ld	b,h
	ld	a,b
} by {
	ld	b,h
	ld	a,h
	; peephole z88dk-606a3
}

replace restart {
	ld	a,c
	ld	d,a
} by {
	ld	a,c
	ld	d,c
	; peephole z88dk-606a4
}

replace restart {
	ld	b,l
	ld	c,%1
	ld	e,b
} by {
	ld	b,l
	ld	c,%1
	ld	e,l
	; peephole z88dk-606a5
}

replace restart {
	ld	c,h
	ld	e,%1
	ld	a,c
} by {
	ld	c,h
	ld	e,%1
	ld	a,h
	; peephole z88dk-606a6
}

replace restart {
	ld	d,l
	ld	e,h
	ld	l,d
} by {
	ld	d,l
	ld	e,h
	; peephole z88dk-606b
}

replace restart {
	ld	d,l
	ld	e,h
	ld	a,e
	or	a,d
} by {
	ld	a,h
	or	a,l
	ld	d,l
	ld	e,h
	; peephole z88dk-606c
}

replace restart {
	ld	e,a
	ld	l,d
	ld	h,e
} by {
	ld	e,a
	ld	l,d
	ld	h,a
	; peephole z88dk-606d
}

replace restart {
	ld	%1,%2
	ld	a, %3
	or	a,%1
} by {
	ld	a, %3
	or	a,%2
	ld	%1,%2
	; peephole z88dk-606e
} if canAssign(%2 '(hl)'), notSame(%1 'a'), operandsNotRelated(%1 %3)

replace restart {
	ld	e,a
	ld	h,e
} by {
	ld	e,a
	ld	h,a
	; peephole z88dk-606f
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,(bc)
} by {
	ld	c,l
	ld	b,h
	ld	a,(hl)
	; peephole z88dk-606g
}

replace restart {
	ld	b,l
	ld	c,h
	ld	a,b
} by {
	ld	b,l
	ld	c,h
	ld	a,l
	; peephole z88dk-606h
}

replace restart {
	ld	c,h
	ld	a,c
} by {
	ld	c,h
	ld	a,h
	; peephole z88dk-606i
}

replace restart {
	ld	a,d
	ld	e,a
} by {
	ld	a,d
	ld	e,d
	; peephole z88dk-606j
}

replace restart {
	ld	b,a
	ld	l, c
	ld	h, b
} by {
	ld	b,a
	ld	l,c
	ld	h,a
	; peephole z88dk-606k
}

replace restart {
	ld	c,l
	ld	b,h
	ld	e, c
} by {
	ld	c,l
	ld	b,h
	ld	e,l
	; peephole z88dk-606l
}

replace restart {
	ld	a, h
	ld	e, l
	ld	d,a
} by {
	ld	a,h
	ld	e,l
	ld	d,h
	; peephole z88dk-606m
}

replace restart {
	ld	e,a
	ld	l,b
	ld	h,e
} by {
	ld	e,a
	ld	l,b
	ld	h,a
	; peephole z88dk-606n
}

replace restart {
	ld	a,d
	ld	b,a
} by {
	ld	a,d
	ld	b,d
	; peephole z88dk-606o
}

replace restart {
	ld	e,l
	ld	d,h
	ld	c,e
} by {
	ld	e,l
	ld	d,h
	ld	c,l
	; peephole z88dk-606p
}

replace restart {
	ld	d,h
	ld	c,l
	ld	b,d
} by {
	ld	d,h
	ld	c,l
	ld	b,h
	; peephole z88dk-606q
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,c
} by {
	ld	c,l
	ld	b,h
	ld	a,l
	; peephole z88dk-606r
}

replace restart {
	ld	l,a
	ld	c,l
} by {
	ld	l,a
	ld	c,a
	; peephole z88dk-606s
}

replace restart {
	ld	a,h
	ld	b,a
} by {
	ld	a,h
	ld	b,h
	; peephole z88dk-606t
}

replace restart {
	ld	l,a
	ld	c,a
	ld	a,h
	ld	b,h
	or	a,l
} by {
	ld	l,a
	ld	c,a
	ld	b,h
	or	a,h
	; peephole z88dk-606u1
}

replace restart {
	ld	b,h
	ld	e,l
	ld	d,b
} by {
	ld	b,h
	ld	e,l
	ld	d,h
	; peephole z88dk-606v
}

replace restart {
	ld	c,l
	ld	a,h
	ld	b,h
	or	a,c
} by {
	ld	c,l
	ld	a,h
	ld	b,h
	or	a,l
	; peephole z88dk-606w
}

replace restart {
	ld	a,b
	ld	c,a
} by {
	ld	a,b
	ld	c,b
	; peephole z88dk-606x1
}

replace restart {
	ld	a,h
	ld	c,a
} by {
	ld	a,h
	ld	c,h
	; peephole z88dk-606x2
}

replace restart {
	ld	c,l
	ld	e,c
} by {
	ld	c,l
	ld	e,l
	; peephole z88dk-606y1
}

replace restart {
	ld	b,l
	ld	c,b
} by {
	ld	b,l
	ld	c,l
	; peephole z88dk-606y2
}

replace restart {
	ld	c,l
	ld	a,c
} by {
	ld	c,l
	ld	a,l
	; peephole z88dk-606y3
}

replace restart {
	ld	c,l
	ld	b,h
	ld	a,d
	or	a, e
	or	a, b
	or	a,c
} by {
	ld	c,l
	ld	b,h
	ld	a,d
	or	a,e
	or	a,h
	or	a,l
	; peephole z88dk-606z
}

replace restart {
	ld	e,a
	ld	l,e
} by {
	ld	e,a
	ld	l,a
	; peephole z88dk-606aa
}

replace restart {
	ld	h,b
	ld	l,c
} by {
	ld	l,c
	ld	h,b
	; peephole z88dk-606ab
}

replace restart {
	ld	e,c
	ld	d,b
	ld	a,e
} by {
	ld	e,c
	ld	d,b
	ld	a,c
	; peephole z88dk-606ac
}

replace restart {
	ld	b,l
	ld	a,h
	ld	d,b
} by {
	ld	b,l
	ld	a,h
	ld	d,l
	; peephole z88dk-606ad0
}

replace restart {
	ld	a,h
	ld	d,l
	ld	e,a
} by {
	ld	a,h
	ld	d,l
	ld	e,h
	; peephole z88dk-606ae0
}

replace restart {
	ld	b,l
	ld	a,h
	ld	d,l
	ld	e,h
	or	a,b
} by {
	ld	b,l
	ld	a,h
	ld	d,l
	ld	e,h
	or	a,l
	; peephole z88dk-606af0
}

replace restart {
	ld	%1,#0x00
	xor	a,a
} by {
	xor	a,a
	ld	%1,a
	; peephole z88dk-606ag1
}

replace restart {
	ld	%1,#0x00
	ld	bc,#0x0000
} by {
	ld	bc,#0x0000
	ld	%1,c
	; peephole z88dk-606ag2
} if operandsNotRelated(%1 'bc')

replace restart {
	ld	%1,#0x00
	ld	de,#0x0000
} by {
	ld	de,#0x0000
	ld	%1,e
	; peephole z88dk-606ag3
} if operandsNotRelated(%1 'de')

replace restart {
	ld	%1,#0x00
	ld	hl,#0x0000
} by {
	ld	hl,#0x0000
	ld	%1,l
	; peephole z88dk-606ag4
} if operandsNotRelated(%1 'hl')

replace restart {
	xor	a,a
	ld	bc,#0x0000
} by {
	xor	a,a
	ld	c,a
	ld	b,a
	; peephole z88dk-606ag5
}

replace restart {
	xor	a,a
	ld	de,#0x0000
} by {
	xor	a,a
	ld	e,a
	ld	d,a
	; peephole z88dk-606ag6
}

replace restart {
	xor	a,a
	ld	hl,#0x0000
} by {
	xor	a,a
	ld	l,a
	ld	h,a
	; peephole z88dk-606ag7
}

replace restart {
	ld	%1,#0x0000
	ld	%2,%3
	xor	a,a
} by {
	xor	a,a
	ld	%1,#0x0000
	ld	%2,%3
	; peephole z88dk-606ag8
} if notSame(%2 'a'), notSame(%3 'a')

replace restart {
	ld	%1,%2
	add	a,%1
} by {
	add	a,%2
	; peephole z88dk-606ad1
} if notUsed(%1), canAssign('(hl)' %2)

replace restart {
	ld	%1,%2
	sub	a,%1
} by {
	sub	a,%2
	; peephole z88dk-606ad2
} if notUsed(%1), canAssign('(hl)' %2)

replace restart {
	ld	%1,%2
	sbc	a,%1
} by {
	sbc	a,%2
	; peephole z88dk-606ad3
} if notUsed(%1), canAssign('(hl)' %2)

replace restart {
	xor	a,a
	ld	%1,%2
	xor	a,a
} by {
	xor	a,a
	ld	%1,%2
	; peephole z88dk-606ae
} if notSame(%1 'a')

replace restart {
	ld	%1,h
	ld	a,l
	sub	a,%2
	ld	a,%1
} by {
	ld	%1,h
	ld	a,l
	sub	a,%2
	ld	a,h
	; peephole z88dk-606af
}

replace restart {
	ld	l,%1
	ld	h,%2
	ld	d,l
} by {
	ld	l,%1
	ld	h,%2
	ld	d,%1
	; peephole z88dk-606ah
} if notSame(%1 'h'), notSame(%1 '(hl)')

replace restart {
	ld	e,l
	ld	a,e
} by {
	ld	e,l
	ld	a,l
	; peephole z88dk-606ai
}

replace restart {
	ld	d,h
	ld	a,d
} by {
	ld	d,h
	ld	a,h
	; peephole z88dk-606aj
}

replace restart {
	ld	%1,%2
	ld	%3 (%4),%1
} by {
	ld	%3 (%4),%2
	ld	%1,%2
	; peephole z88dk-606ak
} if canAssign(%2 '(hl)')

replace restart {
	ld	a,l
	ld	e,a
} by {
	ld	a,l
	ld	e,l
	; peephole z88dk-606al
}

replace restart {
	ld	a,b
	ld	h,a
} by {
	ld	a,b
	ld	h,b
	; peephole z88dk-606am
}

replace restart {
	ld	%1,#0x00
	ld	%2,%3
	ld	%4,#0x00
} by {
	ld	%1,#0x00
	ld	%2,%3
	ld	%4,%1
	; peephole z88dk-606an1
} if notSame(%1 %2), canAssign(%1 '(hl)')

replace restart {
	ld	%1,#0x00
	ld	%4,#0x00
} by {
	ld	%1,#0x00
	ld	%4,%1
	; peephole z88dk-606an2
} if canAssign(%1 '(hl)')

replace restart {
	ld	b,h
	ld	e,b
} by {
	ld	b,h
	ld	e,h
	; peephole z88dk-606ao
}

replace restart {
	ld	b,h
	ld	e,h
	ld	c,b
} by {
	ld	b,h
	ld	e,h
	ld	c,h
	; peephole z88dk-606ap
}

replace restart {
	ld	a,h
	ld	c,l
	ld	b,h
	ld	h,a
} by {
	ld	a,h
	ld	c,l
	ld	b,h
	; peephole z88dk-606aq
}

replace restart {
	ld	l,h
	ld	d,b
	ld	a,l
} by {
	ld	l,h
	ld	d,b
	ld	a,h
	; peephole z88dk-606ar
}

replace restart {
	ld	l,h
	ld	d,b
	ld	a,h
	ld	e,l
} by {
	ld	l,h
	ld	d,b
	ld	a,h
	ld	e,h
	; peephole z88dk-606as
}

replace restart {
	ld	b,l
	ld	d,b
} by {
	ld	b,l
	ld	d,l
	; peephole z88dk-606at
}

replace restart {
	ld	b,l
	ld	d,l
	ld	a,h
	ld	e,h
	or	a,b
} by {
	ld	b,l
	ld	d,l
	ld	a,h
	ld	e,h
	or	a,l
	; peephole z88dk-606au
}

replace restart {
	ld	a,l
	ld	c,a
} by {
	ld	a,l
	ld	c,l
	; peephole z88dk-606av
}

replace restart {
	ld	b,h
	ld	e,l
	ld	a,b
} by {
	ld	b,h
	ld	e,l
	ld	a,h
	; peephole z88dk-606aw
}

replace restart {
	ld	e,l
	ld	a,h
	ld	d,h
	or	a,e
} by {
	ld	e,l
	ld	a,h
	ld	d,h
	or	a,l
	; peephole z88dk-606ax
}

replace restart {
	ld	b,h
	ld	c,a
	ld	a,b
} by {
	ld	b,h
	ld	c,a
	ld	a,h
	; peephole z88dk-606ay
}

replace restart {
	ld	%1,%2
	ld	%3,%4
	ld	%2,%1
} by {
	ld	%1,%2
	ld	%3,%4
	; peephole z88dk-606az
} if notSame(%1 %3), notSame(%2 %3), same(%1 'a' 'b' 'c' 'd' 'e' 'h' 'l'), same(%2 'a' 'b' 'c' 'd' 'e' 'h' 'l')

replace restart {
	ld	hl,#%1
} by {
	; peephole z88dk-607a
} if notUsed('hl')

replace restart {
	ld	hl,#%1 + %2
} by {
	; peephole z88dk-607b
} if notUsed('hl')

replace restart {
	ld	de,#%1
} by {
	; peephole z88dk-607c
} if notUsed('de')

replace restart {
	ld	de,#%1 + %2
} by {
	; peephole z88dk-607d
} if notUsed('de')

replace restart {
	ld	bc,#%1
} by {
	; peephole z88dk-607e
} if notUsed('bc')

replace restart {
	ld	bc,#%1 + %2
} by {
	; peephole z88dk-607f
} if notUsed('bc')

replace restart {
	ld	%1,#(%2 + %3) + %4
} by {
	; peephole z88dk-607g
} if notUsed(%1)
// notVolatile

replace restart {
	ld	%1,#%2 + %3 + %4
} by {
	; peephole z88dk-607h
} if notUsed(%1)

replace restart {
	ld	de,(#%1)
	ld	hl,#%2 + %3
	ex	de,hl
} by {
	ld	hl,(#%1)
	ld	de,#%2 + %3
	; peephole z88dk-608a
}

replace restart {
	ld	de,%1
	ld	hl,%2
	ex	de,hl
} by {
	ld	de,%2
	ld	hl,%1
	; peephole z88dk-608b
}

replace restart {
	ld	de,%1
	ex	de,hl
} by {
	ld	hl,%1
	; peephole z88dk-608c
} if notUsed('de')

replace restart {
	ld	hl,%1
	ex	de,hl
} by {
	ld	de,%1
	; peephole z88dk-608d
} if notUsed('hl')

replace restart {
	ld	bc,(#%1)
	ld	de,(#%2)
	ld	l,c
	ld	h,b
} by {
	ld	hl,(#%1)
	ld	de,(#%2)
	ld	c,l
	ld	b,h
	; peephole z88dk-608e1
}

replace restart {
	ld	bc,(#%1 + %3)
	ld	de,(#%2 + %4)
	ld	l,c
	ld	h,b
} by {
	ld	hl,(#%1 + %3)
	ld	de,(#%2 + %4)
	ld	c,l
	ld	b,h
	; peephole z88dk-608e2
}

replace restart {
	ld	%1,#%2 + 0
} by {
	ld	%1,#%2
	; peephole z88dk-609a
}

replace restart {
	ld	%1,(#%2 + 0)
} by {
	ld	%1,(#%2)
	; peephole z88dk-609b
}

replace restart {
	ld	%1,#%2 + 0 + %3
} by {
	ld	%1,#%2 + %3
	; peephole z88dk-609c
}

replace restart {
	ld	%1,(#%2 + 0 + %3)
} by {
	ld	%1,(#%2 + %3)
	; peephole z88dk-609d
}

replace restart {
	ld	%1,#%2 + %3 + 0
} by {
	ld	%1,#%2 + %3
	; peephole z88dk-609e
}

replace restart {
	ld	%1,(#%2 + %3 + 0)
} by {
	ld	%1,(#%2 + %3)
	; peephole z88dk-609f
}

replace restart {
	ld	%4,(#(%1 + %2) + %3)
} by {
	ld	%4,(#%1 + %2 + %3)
	; peephole z88dk-609g
}

replace restart {
	ld	%4,(#(%1 + %2))
} by {
	ld	%4,(#%1 + %2)
	; peephole z88dk-609h
}

//replace restart {
//	ld	hl,#%1 + %2
//	push	de
//} by {
//	push	de
//	ld	hl,#%1 + %2
//	; peephole z88dk-610a - what benefit in swapping these instructions?
//}

//replace restart {
//	ld	hl,#%1
//	push	de
//} by {
//	push	de
//	ld	hl,#%1
//	; peephole z88dk-610b - what benefit in swapping these instructions?
//}

replace restart {
	ld	((%1 + %2)),%3
} by {
	ld	(%1 + %2),%3
	; peephole z88dk-611a
}

replace restart {
	ld	%3,#<((%1 + %2))
} by {
	ld	%3,#<(%1+%2)
	; peephole z88dk-611b
}

replace restart {
	ld	%3,#>((%1 + %2))
} by {
	ld	%3,#>(%1+%2)
	; peephole z88dk-611c
}

replace restart {
	add	a,#<((%1 + %2))
} by {
	add	a,#<(%1+%2)
	; peephole z88dk-611d
}

replace restart {
	add	a,#>((%1 + %2))
} by {
	add	a,#>(%1+%2)
	; peephole z88dk-611e
}

replace restart {
	adc	a,#<((%1 + %2))
} by {
	adc	a,#<(%1+%2)
	; peephole z88dk-611f
}

replace restart {
	adc	a,#>((%1 + %2))
} by {
	adc	a,#>(%1+%2)
	; peephole z88dk-611g
}

replace restart {
	sub	a,#<((%1 + %2))
} by {
	sub	a,#<(%1+%2)
	; peephole z88dk-611h
}

replace restart {
	sub	a,#>((%1 + %2))
} by {
	sub	a,#>(%1+%2)
	; peephole z88dk-611i
}

replace restart {
	sbc	a,#<((%1 + %2))
} by {
	sbc	a,#<(%1+%2)
	; peephole z88dk-611j
}

replace restart {
	sbc	a,#>((%1 + %2))
} by {
	sbc	a,#>(%1+%2)
	; peephole z88dk-611k
}

replace restart {
	ld	%1,#%2 + 1 + 1
} by {
	ld	%1,#%2 + 2
	; peephole z88dk-611l1
}

replace restart {
	ld	%1,#%2 + 2 + 1
} by {
	ld	%1,#%2 + 3
	; peephole z88dk-611l2
}

replace restart {
	ld	%1,#%2 + 3 + 1
} by {
	ld	%1,#%2 + 4
	; peephole z88dk-611l3
}

replace restart {
	ld	(#%1 + 1 + 1),%2
} by {
	ld	(#%1 + 2),%2
	; peephole z88dk-611l4
}

replace restart {
	ld	((%1 + %2)+%3),%4
} by {
	ld	(%1 + %2 + %3),%4
	; peephole z88dk-612a
}

replace restart {
	and	a,%1
	and	a,%1
} by {
	and	a,%1
	; peephole z88dk-613a
} if notVolatile(%1)

replace restart {
	or	a,%1
	or	a,%1
} by {
	or	a,%1
	; peephole z88dk-613b
} if notVolatile(%1)

//replace restart {
//	ld	hl,#0xFFFF
//	add	hl,de
//} by {
//	ld	l,e
//	ld	h,d
//	dec	hl
//	; peephole z88dk-614a  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	hl,#0xFFFF
//	add	hl,bc
//} by {
//	ld	l,c
//	ld	h,b
//	dec	hl
//	; peephole z88dk-614b  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	hl,#0x0001
//	add	hl,de
//} by {
//	ld	l,e
//	ld	h,d
//	inc	hl
//	; peephole z88dk-614c  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	hl,#0x0001
//	add	hl,bc
//} by {
//	ld	l,c
//	ld	h,b
//	inc	hl
//	; peephole z88dk-614d  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	bc,#0xFFFF
//	add	hl,bc
//} by {
//	ld	bc,#0xFFFF
//	dec	hl
//	; peephole z88dk-614e  INCORRECT IF FLAGS USED
//}
// trashes 32-bit math

//replace restart {
//	ld	de,#0xFFFF
//	add	hl,de
//} by {
//	ld	de,#0xFFFF
//	dec	hl
//	; peephole z88dk-614f  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	bc,#0x0001
//	add	hl,bc
//} by {
//	ld	bc,#0x0001
//	inc	hl
//	; peephole z88dk-614g  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	de,#0x0001
//	add	hl,de
//} by {
//	ld	de,#0x0001
//	inc	hl
//	; peephole z88dk-614h  INCORRECT IF FLAGS USED
//}

//replace restart {
//	ld	a,%1
//	add	a,#0xFF
//	ld	%1,a
//} by {
//	dec	%1
//	ld	a,%1
//	; peephole z88dk-615  INCORRECT IF FLAGS USED
//} if canAssign(%1 '#0xFF')

replace restart {
	ld	%1,#%2 + 1 - 1
} by {
	ld	%1,#%2
	; peephole z88dk-616a
}

replace restart {
	ld	%1,#%2 + 2 - 1
} by {
	ld	%1,#%2 + 1
	; peephole z88dk-616b
}

replace restart {
	ld	%1,#%2 + 3 - 1
} by {
	ld	%1,#%2 + 2
	; peephole z88dk-616c
}

replace restart {
	ld	%1,(#%2 + 1 - 1)
} by {
	ld	%1,(#%2)
	; peephole z88dk-617a
}

replace restart {
	ld	%1,(#%2 + 2 - 1)
} by {
	ld	%1,(#%2 + 1)
	; peephole z88dk-617b
}

replace restart {
	ld	%1,(#%2 + 3 - 1)
} by {
	ld	%1,(#%2 + 2)
	; peephole z88dk-617c
}

replace restart {
	ld	bc,(%1)
	push	bc
} by {
	ld	hl,(%1)
	push	hl
	; peephole z88dk-618a
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	de,(%1)
	push	de
} by {
	ld	hl,(%1)
	push	hl
	; peephole z88dk-618b
} if notUsed('de'), notUsed('hl')

replace restart {
	ld	bc,(%1 + %2)
	push	bc
} by {
	ld	hl,(%1 + %2)
	push	hl
	; peephole z88dk-618c
} if notUsed('bc'), notUsed('hl')

replace restart {
	ld	de,(%1 + %2)
	push	de
} by {
	ld	hl,(%1 + %2)
	push	hl
	; peephole z88dk-618d
} if notUsed('de'), notUsed('hl')

replace restart {
	ex	de,hl
	srl	d
	rr	e
} by {
	srl	h
	rr	l
	ex	de,hl
	; peephole z88dk-619a
}

replace restart {
	ex	de,hl
	sra	d
	rr	e
} by {
	sra	h
	rr	l
	ex	de,hl
	; peephole z88dk-619b
}

replace restart {
	ex	de,hl
	sla	e
	rl	d
} by {
	add	hl,hl
	ex	de,hl
	; peephole z88dk-619c
}

replace restart {
	ld	h,%1
	ld	l,%2
	ld	a,h
	ld	h,l
	ld	l,a
} by {
	ld	l,%1
	ld	h,%2
	ld	a,l
	; peephole z88dk-620a
}

//replace restart {
//	ld	%1,%2
//	pop	%3
//} by {
//	pop	%3
//	ld	%1,%2
//	; peephole z88dk-621 - what benefit in swapping these instructions?
//} if operandsNotRelated(%1 %3), operandsNotRelated(%2 %3), notSame(%1 'sp'), notSame(%3 'ix')

replace restart {
	ld	c,l
	ld	b,h
	pop	hl
	push	bc
} by {
	ld	c,l
	ld	b,h
	ex	(sp),hl
	; peephole z88dk-622a
}

replace restart {
	ld	c,l
	ld	b,h
	ex	(sp),hl
	ld	l,c
	ld	h,b
} by {
	pop	bc
	push	hl
	ld	c,l
	ld	b,h
	; peephole z88dk-622b
}

replace restart {
	push	%1
	pop	%2
} by {
	; peephole z88dk-623
} if notUsed(%2)












replace restart {
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
} by {
	rla
	rl	%1
	sbc	a,a
	ld	b,a
	ld	a,%1
	ld	%1,b
	; peephole z88dk-700a
} if notSame(%1 'b'), notUsed('b')

replace restart {
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
} by {
	rla
	rl	%1
	sbc	a,a
	ld	c,a
	ld	a,%1
	ld	%1,c
	; peephole z88dk-700b
} if notSame(%1 'c'), notUsed('c')

replace restart {
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
} by {
	rla
	rl	%1
	sbc	a,a
	ld	d,a
	ld	a,%1
	ld	%1,d
	; peephole z88dk-700c
} if notSame(%1 'd'), notUsed('d')

replace restart {
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
} by {
	rla
	rl	%1
	sbc	a,a
	ld	e,a
	ld	a,%1
	ld	%1,e
	; peephole z88dk-700d
} if notSame(%1 'e'), notUsed('e')

replace restart {
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
} by {
	rla
	rl	%1
	sbc	a,a
	ld	l,a
	ld	a,%1
	ld	%1,l
	; peephole z88dk-700e
} if notSame(%1 'l'), notUsed('l')

replace restart {
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
	sra	%1
	rra
} by {
	rla
	rl	%1
	sbc	a,a
	ld	h,a
	ld	a,%1
	ld	%1,h
	; peephole z88dk-700f
} if notSame(%1 'h'), notUsed('h')

replace restart {
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
} by {
	rla
	rl	%1
	ld	a,%1
	; peephole z88dk-701a
} if notUsed(%1)

replace restart {
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
	srl	%1
	rra
} by {
	rla
	rl	%1
	ld	a,%1
	ld	%1,#0x00
	rl	%1
	; peephole z88dk-701b
}


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// POISON REMOVE
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

barrier

replace {
	z88dk_poison
} by {
	; poison removal
}


///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// SDCC PEEPHOLE RULES JP->JR ONLY FROM #9570
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

// peeph-z80.def - Z80 peephole rules
//
// Some of these peepholes could be potentially moved to peeph.def, but a
// GBZ80 expert should have a look at them before.
//
// (c) Philipp Klaus Krause (pkk@spth.de, philipp@colecovision.eu) 2006 - 2012
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

// These ex-generating rules should be among the last ones since ex counts as a read from both hl and de for notUsed().
barrier

replace restart {
	ld	d,h
	ld	e,l
} by {
	; peephole 146 used ex to load hl into de.
	ex	de,hl
} if notUsed('hl')

replace restart {
	ld	e,l
	ld	d,h
} by {
	; peephole 147 used ex to load hl into de.
	ex	de,hl
} if notUsed('hl')

replace restart {
	ld	l,e
	ld	h,d
} by {
	; peephole 148 used ex to load de into hl.
	ex	de,hl
} if notUsed('de')

barrier

// Should be one of the last ones. Opens the code to further peephole optimization.
replace restart {
%1:
} by {
	; peephole 149 removed unused label %1.
} if labelRefCount(%1 0)

// Ensure that all rules above see only jp, not jr.
barrier

replace {
	add	hl,de
	pop	de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
%2:
} by {
	; peephole 150-3 removed addition using short jumps in jump-table.
	pop	de
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
%2:
} if labelJTInRange

replace {
	add	hl,de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
%2:
} by {
	; peephole 150-3' removed addition using short jumps in jump-table.
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
%2:
} if labelJTInRange

replace {
	add	hl,de
	pop	de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
%2:
} by {
	; peephole 150-4 removed addition using short jumps in jump-table.
	pop	de
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
%2:
} if labelJTInRange

replace {
	add	hl,de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
%2:
} by {
	; peephole 150-4' removed addition using short jumps in jump-table.
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
%2:
} if labelJTInRange

replace {
	add	hl,de
	pop	de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
	jp	%9
%2:
} by {
	; peephole 150-5 removed addition using short jumps in jump-table.
	pop	de
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
	jr	%9
%2:
} if labelJTInRange

replace {
	add	hl,de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
	jp	%9
%2:
} by {
	; peephole 150-5' removed addition using short jumps in jump-table.
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
	jr	%9
%2:
} if labelJTInRange

replace {
	add	hl,de
	pop	de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
	jp	%9
	jp	%10
%2:
} by {
	; peephole 150-6 removed addition using short jumps in jump-table.
	pop	de
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
	jr	%9
	jr	%10
%2:
} if labelJTInRange

replace {
	add	hl,de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
	jp	%9
	jp	%10
%2:
} by {
	; peephole 150-6' removed addition using short jumps in jump-table.
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
	jr	%9
	jr	%10
%2:
} if labelJTInRange

replace {
	add	hl,de
	pop	de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
	jp	%9
	jp	%10
	jp	%11
%2:
} by {
	; peephole 150-7 removed addition using short jumps in jump-table.
	pop	de
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
	jr	%9
	jr	%10
	jr	%11
%2:
} if labelJTInRange

replace {
	add	hl,de
	jp	(hl)
%1:
	jp	%5
	jp	%6
	jp	%7
	jp	%8
	jp	%9
	jp	%10
	jp	%11
%2:
} by {
	; peephole 150-7' removed addition using short jumps in jump-table.
	jp	(hl)
%1:
	jr	%5
	jr	%6
	jr	%7
	jr	%8
	jr	%9
	jr	%10
	jr	%11
%2:
} if labelJTInRange

barrier

// Do all jump optimizations before replacing by ret.

replace restart {
	jp	%5
} by {
	ret
	; peephole 151 replaced jump by return.
} if labelIsReturnOnly(%5), labelRefCountChange(%5 -1)

replace restart {
	jp	%1,%5
} by {
	ret	%1
	; peephole 152 replaced jump by return.
} if labelIsReturnOnly(%5), labelRefCountChange(%5 -1)

// Replace jp by ret before replacing jp by jr outside of jump tables, since using ret can reduce the number of references to jump labels.
barrier

replace {
	jp	%5
} by {
	jr	%5
	; peephole 153 changed absolute to relative unconditional jump.
} if labelInRange(%5)

replace {
	jp	Z,%5
} by {
	jr	Z,%5
	; peephole 154 changed absolute to relative conditional jump.
} if labelInRange(%5)

replace {
	jp	NZ,%5
} by {
	jr	NZ,%5
	; peephole 155 changed absolute to relative conditional jump.
} if labelInRange(%5)

replace {
	jp	C,%5
} by {
	jr	C,%5
	; peephole 156 changed absolute to relative conditional jump.
} if labelInRange(%5)

replace {
	jp	NC,%5
} by {
	jr	NC,%5
	; peephole 157 changed absolute to relative conditional jump.
} if labelInRange(%5)

replace {
	dec b
	jr	NZ,	%5	
} by {
	djnz	%5
	; peephole 156 used djnz
}
